논문 잘 쓰기

대학원 다니던 시절(2003.01.12 )에 **동호회에 쓴 글을 옮겨왔습니다.

제 지도교수들이랑 같이 모니터 앞에 앉아서 논문 고친적이 꽤 되는데
그러면서 많은 얘기들을 들어서 그것들을 한번 정리해 봤는데요.
저도 다른사람들 논문을 심사해 보면서 교수들 말에 많이 공감하게 되더군요.

더 보충할 내용이나 다르게 생각되는 부분이 있으면 답글 적어주세요. ^^

이공계, 특히 실험보다는 수학,이론,알고리즘 관련 분야에서의 논문쓸때 염두에 둘 사항들...
(아마도 다른 분야에서도 비슷하리라 봅니다만...)
  1. 필요하다면 언제라도 처음부터 완전히 다시 써라. 아이디어는 항상 발전한다.
  2. 극도로 명확하지 않은 내용은 아예 쓰지 말라.
  3. 명확성과 아름다움이 충돌할 때는 항상 명확성을 선택하라.
  4. 내용을 절제하라. 너무 많은 내용을 담으려 하면 난해한 논문이 되기 쉽다.
  5. 독자가 최소한의 배경지식만을 가지고 있다고 가정하라.
  6. 최대한 앞부분을 쉽고 평이하게 쓰라. 상당수의 독자는 앞부분만을 읽는다는 것을 유의하라.
  7. 서론은 예술이다. 단어 하나, 문장 하나, 참고문헌 인용 하나하나가 특정한 의미를 함축하고 전체적으로 기능하도록 하라.
  8. 직관은 최대한 배제하고 논리에 의존하라. 직관적인 설명은 speculation의 위험이 있다.
  9. 참고문헌을 인용할때는 자신의 논문이 어떤 맥락에서 그 연장선에 있는지, 차별점이 무엇인지를 단 한문장으로 요약할만큼 명확히 이해한 후에, 논문에 실제 기술할 문장을 작성하기 시작하라.
  10. 다른 사람의 접근방법을 비판할때는 최대한 간략히 하라. 긴 비판은 옳고 그르고를 떠나 반발하고 싶은 심리를 불러 일으킨다.
  11. 용어,기호들은 최대한 명확히 정의한 후에 사용하라.
  12. 문장이 암시적으로 내포하는 의미에 대해서도 충분히 검토하라.
  13. 데이터는 해석보다는 단순설명에 주력하라.
  14. 거짓데이터 뿐만 아니라 부정확한 설명, 심지어 오해가능한 설명도 학문적 사기임을 명심하라.
  15. (특히 native speaker가 아닌 경우에는) 단순한 문장구조를 택하라.
  16. 논문을 제출한 후에는 (틀린 내용이 아니라면) 리뷰어의 요구사항이 아니라면 수정하지 말라. 요구받지 않은 수정은 리뷰어를 혼란시키고, 수정의 욕구는 끝이 없기 때문이다.
  17. 리뷰어와의 논쟁을 피하라. 옳고 그르고를 떠나서 심리학적으로 불리하다.
  18. 리뷰어의 요구사항은 완전히 잘못된 것이 아니라면 무조건 들어주라.

가장 중요한 걸 빼먹었당.
     0. 많은 편수의 논문을 쓰려 하지 마라. 논문쓰기는 지루하고 고통스럽고 덜 생산적인 작업이다.


원본글 http://rainyvale.puppynbunny.com/19
2010/05/17 16:01 2010/05/17 16:01
Paper 2010/05/17 16:01

접속사, 접속부사 정리


   그러나, 하지만     however, but, yet


   반면에            on the other hand, while,

                         whereas


   그와는 반대로      on the contrary


   대조적으로        in contrast


   …에도 불구하고    in spite of, despite, with all,

                         for all, nevertheless, still

                      nonetheless,


   또한              also, … as well



   게다가            besides, moreover, furthermore,

                         what is more, in addition


   …에 덧붙여서,     in addition to, on top of


   결국              as a result, consequently,

                       eventually, in the end,

                      in the long run


   그러므로, 따라서   therefore, hence, so, thus

                      accordingly


   그런데(화제전환)   by the way


   예를 들면         for example, for instance,

                      such as


   무엇보다도, 우선   above all, first of all,

                      to begin with


   처음에            for one thing, at first, firstly,

                      in the first place


   그리고 나서       then(‘그때에’라는 뜻도 있음)


   그러는 동안       meanwhile, in the meantime


   후에, 나중에       afterwards, later


   마지막으로        finally, at last


   동시에            at the same time,

                      simultaneously


   즉, 다시 말해서    that is (to say), namely,

                      so to speak, in other words


   간단히 말해서,     in short, in brief, in summary,

     요컨대            in a word, to sum up


   마찬가지로        similarly, likewise, equally,

                      in the same way


   만약 그렇지 않으면 otherwise


   (…와) 비교하여    in comparison (with/to)


 … 대신에          instead (of)

2010/04/27 20:38 2010/04/27 20:38
English 2010/04/27 20:38

Mathematical and scientific symbols

Mathematical and scientific symbols

Common pronunciations of mathematical and scientific symbols are given in the list below.

(all the pages in this section need a unicode font installed - e.g. Arial Unicode MS, Doulos SIL Unicode, Lucida Sans Unicode - see: The International Phonetic Alphabet in Unicode).

Symbols

+ plus /'plʌs/
- minus /'maɪnəs/
± plus or minus /'plʌs  ɔ:  'maɪnəs/
x multiplied by /'mʌltɪplaɪd baɪ/
/ over; divided by /'əʊvə/ /dɪ'vaɪdəd/
÷ divided /dɪ'vaɪdəd/
= equals /'ɪ:kwəlz/
approximately, similar /ə'prɒksɪmətlɪ/ /'sɪmɪlə tʊ/
equivalent to; identical /ɪk'wɪvələnt tʊ/ /aɪ'dentɪkl tʊ/
not equal to /'nɒt 'iːkwəl tʊ/
> greater than /'greɪtə ðən/
< less than /'les ðən/
greater than or equal to /'greɪtə ðən ər 'iːkwəl tʊ/
less than or equal to /'les ðən ər' iːkwəl tʊ/
not greater than /'nɒt 'greɪtə ðən/
not less than /'nɒt 'les ðən/
much greater than /'mʌʧ 'greɪtə ðən/
much less than /'mʌʧ 'les ðən/
perpendicular to /pɜːpən'dɪkjʊlə tʊ/
∣∣ parallel to /'pærəlel tʊ/
not equivalent to, not identical to /'nɒt ɪk'wɪvələnt tʊ/ /'nɒt aɪ'dentɪkl tʊ/
≄≉ not similar to /'nɒt 'sɪmɪlə tʊ/
² squared /'skweəd/
³ cubed /'kju:bd/
4 to the fourth;  to the power four /tə ðə 'fɔːθ/ /te ðə 'pɑʊə fɔː/
n  to the n; to the nth; to the power n /tə ðɪ en; tə dɪ enθ; tə ðə pɑʊər en/
root; square root /ru:t/ /skweə ru:t/
cube root /kju:b ru:t/
fourth root /fɔːθ ruːt/
! factorial /fæk'tɔːrɪəl/
% percent /pə'sent/
infinity /ɪn'fɪnətɪ/
varies as; proportional to /'vɛərɪz/  /prə'pɔːʃənəl/
˙ dot /dɒt/
¨ double dot /dʌbl dɒt/
: is to, ratio of /reɪʃɪəʊ/
f(x) fx f; function /ef/ /'fʌŋkʃən/
f'(x) f dash; derivative /dæʃ/ /dɪ'rɪvətɪv/
f''x f double-dash; second derivative /'dʌbl dæʃ/ /'sekənd dɪ'rɪvətɪv/
f'''(x) f triple-dash; f treble-dash; third derivative /'trɪpl dæʃ/ / trebl dæʃ/ /θɜ:d dɪ'rɪvətɪv/
f(4) f four; fourth derivative /fɔːθ dɪ'rɪvətɪv/
partial derivative, delta /paːʃəl dɪ'rɪvətɪv/ /deltə/
integral /'ɪntɪgrəl/
sum /sʌm/
w.r.t. with respect to /wɪð 'rɪspekt/
log log /lɒg/
logx log to the base 2 of x /lɒg tə ðə beɪs tu: əv eks/
therefore /'ðɛəfɔː/
because /bɪ'kɒz/
gives, leads to, approaches /gɪvz/ /li:dz tʊ/ /əprəʊʧəz/
/ per /pɜ:/
belongs to; a member of;  an element of /bɪ'lɒŋz/ /'membə/ /'elɪmənt/
does not belong to; is not a member of; is not an element of /nɒt bɪ'lɒŋ/ /nɒt ə 'membə/ /nɒt ən 'elɪmənt/
contained in;  a proper subset of /kən'teɪnd ɪn/ /'prɒpə 'sʌbset/
contained in; subset /'sʌbset/
intersection /'ɪntəsekʃən/
union /'juːnɪən/
for all /fə rɔ:l/
cos x cos x; cosine x /kɒz/
sin x sine x /saɪn/
tan x tangent x /tan/
cosec x cosec x /'kəʊsek/
sinh x shine x /'ʃaɪn/
cosh x cosh x /'kɒʃ/
tanh x than x /θæn/
|x| mod x; modulus x /mɒd/ /'mɒdjʊləs/
degrees Centigrade /dɪ'gri:z 'sentɪgreɪd/
degrees Fahrenheit /dɪ'gri:z 'færənhaɪt/
°K degrees Kelvin /dɪ'gri:z 'kelvɪn/
0°K, –273.15 °C absolute zero /absəlu:t zi:rəʊ/
mm millimetre /'mɪlɪmiːtə/
cm centimetre /'sentɪmiːtə/
cc, cm³ cubic centimetre, centimetre cubed /'kjuːbɪk 'sentɪmiːtə/ /'sentɪmiːtə 'kju:bd/
m metre /'miːtə/
km kilometre /kɪ'lɒmɪtə/
mg milligram /'mɪlɪgræm/
g gram /græm/
kg kilogram /'kɪləgræm/
AC A.C. /eɪ si:/
DC D.C. /di: si:/

^

Examples

x + 1 x plus one
x -1 x minus one
x ± 1 x plus or minus one
xy x y;  x times y; x multiplied by y
(x — y)(x + y)  x minus y, x plus y
x/y x over y;  x divided by y;
x ÷ y x divided by y
x = 5 x equals 5;  x is equal to 5
x ≈ y x is approximately equal to y
x ≡ y x is equivalent to y;  x is identical with y
x ≠ y x is not equal to y
x > y  x is greater than y
x < y  x is less than y
x ≥ y x is greater than or equal to y
x ≤ y x is less than or equal to y
0 < x < 1 zero is less than x is less than 1; x is greater than zero and less than 1
0 ≤ x ≤ 1 zero is less than or equal to x is less than or equal to 1; x is greater than or equal to zero and less than or equal to 1
x squared
x cubed
x4 x to the fourth;  x to the power four
xn x to the n; x to the nth;  x to the power n
x-n x to the minus n;  x to the power of minus n
root x; square root x; the square root of x
the cube root of x
the fourth root of x
the nth root of x
(x + y)² x plus y all squared
(x/y)² x over y all squared
n! n factorial; factorial n
x% x percent
infinity
x ∝ y x varies as y; x is (directly) proportional to y
x ∝ 1/y x varies as one over y; x is indirectly proportional to y
x dot
x double dot
f(x) fx f of x; the function of x
f'(x) f dash x; the (first) derivative of with respect to x
f''x f double-dash x; the second derivative of f with respect to x
f'''(x) f triple-dash x; f treble-dash x; the third derivative of f with respect to x
f(4) f four x; the fourth derivative of f with respect to x
∂v the partial derivative of v
∂v
∂θ
delta v by delta theta, the partial derivative of v with respect to θ
²v
∂θ²
delta two v by delta theta squared; the second partial derivative of v with respect to θ
dv the derivative of v
dv
d v by d theta, the derivative of v with respect to theta
d²v
²
d 2 v by d theta squared, the second derivative of v with respect to theta,
integral
integral integral from zero to infinity
sum
the sum from i equals 1 to n
w.r.t. with respect to
logey log to the base e of y; log y to the base e; natural log (of) y
therefore
because
gives, approaches
Δx → 0 delta x approaches zero
lim
Δx→0
the limit as delta x approaches zero, the limit as delta x tends to zero
Lt
Δx→0
the limit as delta x approaches zero, the limit as delta x tends to zero
m/sec metres per second
x ∈ A x belongs to A; x is a member of A; x is an element of A
x∉ A x does not belong to A; x is not  a member of A; x is not an element of A
A⊂ B A is contained in B; A is a proper subset of B
A ⊆ B A is contained in B; A is a subset of B
A ⋂ B A intersection B
A ⋃ B A union B
cos x cos x; cosine x
sin x sine x
tan x tangent x, tan x
cosec x cosec x
sinh x shine x
cosh x cosh x
tanh x than x
|x| mod x; modulus x
18 ℃ eighteen degrees Centigrade
70 ℉ seventy degrees Fahrenheit

^

Greek alphabet

Α α alpha /'ælfə/
Β β beta /'bi:tə/
Γ γ gamma /'gæmə/
Δ δ delta /'deltə/
Ε ε epsilon /'epsilən/
Ζ ζ zeta /'ziːtə/
Η η eta /'iːtə/
Θ θ theta /'θiːtə/
Ι ι iota /aɪ'əʊtə/
Κ κ kappa /'kæpə/
Λ λ lamda /'læmdə/
Μ μ mu /'mjuː/
Ν ν nu /'njuː/
Ξ ξ xi /'ksaɪ/
Ο ο omicron /'əʊmɪkrən/
Π π pi /'paɪ/
Ρ ρς rho /'rəʊ/
Σ σ sigma /'sɪgmə/
Τ τ tau /'tɑʊ/
Υ υ upsilon /'jʊpsɪlən/
Φ φ phi /'faɪ/
Χ χ chi /'kaɪ/
Ψ ψ psi /'psaɪ/
Ω ω omega /'əʊmɪgə/

^

Roman alphabet

A a /'eɪ/
B b /'biː/
C c /'siː/
D d /'diː/
E e /'iː/
F f /'ef/
G g /'ʤiː/
H h /'eɪʧ/
I i /'aɪ/
J j /'ʤeɪ/
K k /'keɪ/
L l /'el/
M m /'em/
N n /'en/
O o /'əʊ/
P p /'piː/
Q q /'kjuː/
R r /'ɑː/
S s /'es/
T t /'ti:/
U u /'ju:/
V v /'vi:/
W w /'dʌbljuː/
X x /'eks/
Y y /'waɪ/
Z z /'zed/

^

Fractions

½ a half /ə 'hɑ:f/
¼ a quarter /ə 'kwɔːtə/
¾ three quarters /θriː 'kwɔːtəz/
a third /ə 'θɜ:d/
two thirds /tu: 'θɜ:dz/
a fifth /ə 'fɪfθ/
two fifths /tu: 'fɪfθs/
three fifths /θriː 'fɪfθs/
four fifths /fɔː 'fɪfθs/
a sixth /ə 'sɪksθ/
five sixths /faɪv 'sɪksθs/
an eighth /ən 'eɪtθ/
three eighths /θriː 'eɪtθs/
five eighths /faɪv 'eɪtθs/
seven eighths /sevən 'eɪtθs/

^

Decimal Fractions

0.1 nought point one /nɔ:t pɔɪnt wʌn/
0.01 nought point oh one /nɔ:t pɔɪnt əʊ wʌn/
0.0001 nought point oh oh oh one /ten pɔɪnt əʊ əʊ əʊ wʌn/
1.1 one point one /wʌn pɔɪnt wʌn/
1.2 one point two /wʌn pɔɪnt tu:/
1.23 one point two three /wʌn pɔɪnt tu: θri:/
1.0123 one point oh one two three /wʌn pɔɪnt əʊ wʌn tu: θri:/
10.01 ten point oh one /ten pɔɪnt əʊ wʌn/
21.57 twenty-one point five seven /'twentɪ wʌn pɔɪnt  faɪv 'sevən/
2.6666666666.... two point six recurring /tu: pɔɪnt  sɪks rɪ'kɜ:rɪŋ/
2.612361236123... two point six one two three recurring /tu: pɔɪnt  sɪks wʌn tu: θri: rɪ'kɜ:rɪŋ/
2.5 million two point five million /tu: pɔɪnt  faɪv 'mɪljən/

^

SI Units: Prefixes

10-24 yocto y /'jɒktəʊ/
10-21 zepto z /'zeptəʊ/
10-18 atto a /'atəʊ/
10-15 femto f /'femtəʊ/
10-12 pico p /'pi:kəʊ/
10-9 nano n /'nanəʊ/
10-6 micro µ /'maɪkrəʊ/
10-3 milli m /'mɪlɪ/
10-2 centi c /'sentɪ/
10-1 deci d /'desɪ/
103 kilo k /'kɪləʊ/
106 mega M /'megə/
109 giga G /'gɪgə/
1012 tera T /'terə/
1015 peta P /'petə/
1018 exa E /'eksə/
1021 zetta Z /'zetə/
1024 yotta Y /'jɒtə/
1027 xona X /'zəʊnə/
1030 weka W /'wekə/
1033 vunda V /'vʊndə/

^

Cardinal Numbers

1 one /wʌn/
2 two /tu:/
3 three /θri:/
4 four /fɔː/
5 five /faɪv/
6 six /sɪks/
7 seven /'sevən/
8 eight /eɪt/
9 nine /naɪn/
10 ten /ten/
11 eleven /ɪ'levən/
12 twelve /twelv/
13 thirteen /θɜ:'ti:n/
14 fourteen /fɔː'ti:n/
15 fifteen /fɪf'ti:n/
16 sixteen /sɪkst'i:n/
17 seventeen /seven'ti:n/
18 eighteen /eɪ'ti:n/
19 nineteen /naɪn'ti:n/
20 twenty /'twentɪ/
21 twenty-one /twentɪ'wʌn/
22 twenty-two /twentɪ'tu:/
23 twenty-three /twentɪ'θri:/
24 twenty-four /twentɪ'fɔː/
25 twenty-five /twentɪ'faɪv/
26 twenty-six /twentɪ'sɪks/
27 twenty-seven /twentɪ'sevən/
28 twenty-eight /twentɪ'eɪt/
29 twenty-nine /twentɪ'naɪn/
30 thirty /'θɜ:tɪ/
40 forty /'fɔːtɪ/
50 fifty /'fɪftɪ/
60 sixty /'sɪkstɪ/
70 seventy /'sevəntɪ/
80 eighty /'eɪtɪ/
90 ninety /'naɪntɪ/
100 a hundred; one hundred /ə 'hʌndrəd/ /wʌn 'hʌndrəd/
101 a hundred and one /ə 'hʌndrəd ən wʌn/
102 a hundred and two /ə 'hʌndrəd ən tu:/
110 a hundred and ten /ə 'hʌndrəd ən ten/
120 a hundred and twenty /ə 'hʌndrəd ən 'twentɪ/
200 two hundred /tu: 'hʌndrəd/
300 three hundred /θri:  'hʌndrəd/
400 four hundred /fɔː 'hʌndrəd/
500 five hundred /faɪv 'hʌndrəd/
600 six hundred /sɪks 'hʌndrəd/
700 seven hundred /'sevən 'hʌndrəd/
800 eight hundred /eɪt 'hʌndrəd/
900 nine hundred /naɪn 'hʌndrəd/
1 000 a thousand, one thousand /ə θ'ɑʊzənd/ /wʌn 'θɑʊzənd/
1 001 a thousand and one /ə 'θɑʊzənd ən wʌn/
1 010 a thousand and ten /ə 'θɑʊzənd ən ten/
1 020 a thousand and twenty /ə 'θɑʊzənd ən 'twentɪ/
1 100 one thousand, one hunded /wʌn 'θɑʊzənd wʌn 'hʌndrəd/
1 101 one thousand, one hundred and one /wʌn 'θɑʊzənd wʌn 'hʌndrəd ən wʌn/
1 110 one thousand, one hundred and ten /wʌn 'θɑʊzənd wʌn 'hʌndrəd ən ten/
9 999 nine thousand, nine hundred and ninety-nine /naɪn 'θɑʊzənd naɪn 'hʌndrəd ən 'naɪntɪ 'naɪn/
10 000 ten thousand /ten 'θɑʊzənd/
15 356 fifteen thousand, three hundred and fifty six /'fɪfti:n 'θɑʊzənd θri: 'hʌndrəd ən 'fɪftɪ sɪks/
100 000 a hundred thousand /ə 'hʌndrəd 'θɑʊzənd/
1 000 000 a million /ə 'mɪljən/
100 000 000 a hundred million /ə 'hʌndrəd 'mɪljən/
1 000 000 000 a billion /ə 'bɪljən/
100 000 000 000 a hundred billion /ə 'hʌndrəd 'bɪljən/
1 000 000 000 000 a trillion /ə 'trɪljən/
1 000 000 000 000 000 a quadrillion /ə kwɒdrɪljən/
1 000 000 000 000 000 000 a quintillian /ə kwɪn'tɪljən/
1 000 000 000 000 000 000 000 a sextillion /ə seks'tɪljən/
1 000 000 000 000 000 000 000 000 a septillion /ə sep'tɪljən/
1 000 000 000 000 000 000 000 000 000 an ocillion /ən ɒkt'tɪljən/
1 000 000 000 000 000 000 000 000 000 000 a nonillion /ə nɒn'ɪljən/
1 000 000 000 000 000 000 000 000 000 000 000 a decillion /ə de'sɪljən/

^

Ordinal Numbers

1st first /fɜ:st/
2nd second /'sekənd/
3rd third /θɜ:d/
4th fourth /fɔ:θ/
5th fifth /fɪfθ/
6th sixth /sɪksθ/
7th seventh /'sevənθ/
8th eighth /eɪtθ/
9th ninth /naɪnθ/
10th tenth /tenθ/
11th eleventh /ɪ'levənθ/
12th twelfth /'twelfθ/
13th thirteenth /θɜ:'ti:nθ/
14th fourtheenth /fɔː'ti:nθ/
15th fidteenth /fɪf'ti:nθ/   
16th sixteenth /sɪks'ti:nθ/
17th seventeenth /seven'ti:nθ/
18th eighteenth /eɪ'ti:nθ/
19th nineteenth /naɪn'ti:nθ/
20th twentieth /'twentɪəθ/
21st twenty-first /twentɪ'fɜ:st/
22nd twenty-second /twentɪ'sekənd/
23rd twenty-third /twentɪ'θɜ:d/
24th twenty-fourth /twentɪ'fɔ:θ/
25th twenty-fifth /twentɪ'fɪfθ/
26th twenty-sixth /twentɪ'sɪksθ/
27th twenty-seventh /twentɪ'sevənθ/
28th twenty-eighth /twentɪ'eɪtθ/
29th twenty-ninth /twentɪ'naɪnθ/
30th thirtieth /'θɜːtɪəθ/
31st thirty-first /θɜːtɪ'fɜ:st/
40th fortieth /'fɔ:tɪəθ/
50th fiftieth /'fɪftɪəθ/
100th hundredth /'hʌndrədθ/
1 000th thousandth /'θɑʊzəndθ/
1 000 000th miilionth /'mɪljənθ/

^


from http://www.uefap.com/speaking/symbols/symbols.htm


2010/04/23 13:50 2010/04/23 13:50
Mathematics 2010/04/23 13:50

메모리 누수 잡기 - 자체 코딩으로

How To Find Memory Leaks

By Dion Picco
23 May 2000

Read This Disclaimer  


--------------------------------------------------------------------------------

Introduction



I was recently working on a rather large project, the largest I had ever been involved with. We didn't have a concrete design document on this project so ideas and implementations were constantly changing. This is a great flexibility from a design/creation standpoint, but from a programming perspective it ended up becoming a rather large mess. Deep into the project we realized that with release date approaching we should tackle the task of cleaning up the garbage code and stabilizing it for alpha testing. Being a small company however meant that programs like BoundsChecker?from NuMega were just not within our reach. So we had to improvise. We needed a drop in solution to our current code base (the code base was entirely C++). We didn't want a project specific fix however. We needed a simple solution that could easily be compiled into this project and any other. Then at the end of runtime it would generate a list of the un-freed memory blocks. Well, of course we found it, otherwise this article would not be. We'll be right back after these messages to bring you the solution!

We're back. Let me elaborate more on exactly what we needed in our "memory tracer". We first needed something that could be added to any existing code base. Code reuse is a very important consideration, especially to a company. It can potentially save hundreds of hours and thousands of dollars. Secondly, our solution had to be simple. We didn't have time nor the courage to wade through thousands of lines of code doing re-writes and fixes to accommodate our memory tracer. And finally, it had to be free.

So we took a look at our code. The first thing we noticed is that nearly all of our memory allocations were accomplished through the operator new and variants. And likewise the de-allocations were accomplished through delete and variants. Well, we could replace all occurrences of new and delete with proprietary functions that tracked our memory for us? No! Too many replacements! C++ allows you to override new and delete in your classes. That would be great news if it didn't mean adding these overrides to all our classes. Wait a minute... I can override the global new and delete operators!!! Now I can do whatever just before each memory allocation and de-allocation! This great news! Sort of. I had actually known about this in a roundabout way. You see, MFC also has this ability. It is exploited through some of the _Crt() functions. Now that we have our back door, all we need to do is to track the allocations and cross-reference them with the de-allocations at destruction time. What doesn't get referenced is a leak. Simple.

Lets get to the workings of it shall we. All my work and references are written using Visual C++. It should be trivial to convert to other vendors. The first thing to do is to override new and delete so that they will be overridden everywhere in the program. In stdafx.h, I add:

      #ifdef _DEBUG
      inline void * __cdecl operator new(unsigned int size,
                                         const char *file, int line)
      {
      };

      inline void __cdecl operator delete(void *p)
      {
      };
      #endif


These are my overridden functions. And by encasing them with #ifdef/#endif quotes, I don't get sub-par code with Release builds. When you look at the code you'll notice that new has been overridden with three parameters. These are the size of the requested allocation as well as the file and line from the source file where the allocation takes place. This is necessary in finding where the leaks are. Otherwise they would take a lot of assembly digging to find. By adding this however, all our code base that calls new() still refers to the operator new function that accepts one parameter, and not our three parameter new function. In addition, we wouldn't want to recode all our new operator statements to include the __FILE__ and __LINE__ arguments. What we need to do is to automatically make the one-parameter new operator call a three-parameter new operator call. This can be accomplished with some macro trickery.

      #ifdef _DEBUG
      #define DEBUG_NEW new(__FILE__, __LINE__)
      #else
      #define DEBUG_NEW new
      #endif
      #define new DEBUG_NEW


Now all of our one-parameter new operator calls are three parameter new calls with the __FILE__ and __LINE__ automatically inserted by the pre-compiler. Now is time for the actual tracking. We should also add the memory routines to our overridden functions so that they at least do what the old new/delete operator functions did.

      #ifdef _DEBUG
      inline void * __cdecl operator new(unsigned int size,
                                         const char *file, int line)
      {
              void *ptr = (void *)malloc(size);
              AddTrack((DWORD)ptr, size, file, line);
              return(ptr);
      };
      inline void __cdecl operator delete(void *p)
      {
              RemoveTrack((DWORD)p);
              free(p);
      };
      #endif


In addition to these, you may also need to override the new[] and delete[] operators as well. They are the same so I just left them out to save space.

Finally we need to supply some code the tracking functions AddTrack() and RemoveTrack(). I use the STL to maintain my linked list of allocations. You can use whatever. They two functions can contain any code you wish and then some. But I'll provide you with my version just in case you have coders block.

      typedef struct {
              DWORD        address;
              DWORD        size;
              char        file[64];
              DWORD        line;
      } ALLOC_INFO;

      typedef list<ALLOC_INFO*> AllocList;

      AllocList *allocList;

      void AddTrack(DWORD addr,  DWORD asize,  const char *fname, DWORD lnum)
      {
              ALLOC_INFO *info;

              if(!allocList) {
                      allocList = new(AllocList);
              }

              info = new(ALLOC_INFO);
              info->address = addr;
              strncpy(info->file, fname, 63);
              info->line = lnum;
              info->size = asize;
              allocList->insert(allocList->begin(), info);
      };

      void RemoveTrack(DWORD addr)
      {
              AllocList::iterator i;

              if(!allocList)
                      return;
              for(i = allocList->begin(); i != allocList->end(); i++)
              {
                      if((*i)->address == addr)
                      {
                              allocList->remove((*i));
                              break;
                      }
              }
      };


Now, at the very last moment before our program exits, allocList is a list of all memory allocations that have not been freed. But in order to see what and where they are, you need to dump the information stored within allocList. I use the output window in Visual C++ for this. You can format this information in any way but what I've provided just dumps the list of information. Note that using the debug output window of Visual C++ may result in some lines of text not getting outputted before it cuts off.

      void DumpUnfreed()
      {
              AllocList::iterator i;
              DWORD totalSize = 0;
              char buf[1024];

              if(!allocList)
                      return;

              for(i = allocList->begin(); i != allocList->end(); i++) {
                      sprintf(buf, "%-50s:\t\tLINE %d,\t\tADDRESS %d\t%d unfreed\n",
                              (*i)->file, (*i)->line, (*i)->address, (*i)->size);
                      OutputDebugString(buf);
                      totalSize += (*i)->size;
              }
              sprintf(buf, "-----------------------------------------------------------\n");
              OutputDebugString(buf);
              sprintf(buf, "Total Unfreed: %d bytes\n", totalSize);
              OutputDebugString(buf);
      };


There you have it. A bit of reusable code that you can use in all your projects to track all your memory leaks. I always add these functions to every project I start working on and I've used them to clean up projects already completed. It may not help make your game look the best, but it will hopefully help stabilize it. Take care everyone and send me any and all comments. 
2010/04/19 18:22 2010/04/19 18:22
Computing 2010/04/19 18:22

Ubuntu에 Boost라이브러리 설치

원문출처: http://www.filepang.co.kr/118

C++에서 정규식을 쓰고 싶어서...쓸만한 라이브러리를 찾다가 boost에 정규식 라이브러리가 포함되 있다는걸 알았다. 기왕 설치할꺼 boost까지 다 깔아봤다. http://www.boost.org 의 Getting Started on Unix Variants 페이지를 참조했다.


 적당히 디렉토리를 하나 만들고 소스코드를 받자. 나는 ~/src 디렉토리에 boost 소스코드를 받았다능. 압축도 좀 풀어주고...


 Getting Started on Unix Variants 페이지의 2.The Boost Distribution 부터 4. Build a Simple Program Using Boost 를 읽고 Build a Simple Program Using Boost 를 따라해보자. 시키는데로 하는게 제일 속 편하다능. 내 경우에 path/to/boost_1_40_0 는 ~/src/boost_1_40_0 가 되었다. 자신이 정한 디렉토리로 path/to/boost_1_40_0를 치환하는걸 잊지말자능.

 이제 섹션 5.1을 따라하자. 아마도 root 퍼미션이 필요할태니....다음과 같이 입력하자.

$ cd path/to/boost_1_40_0
$ ./bootstrap.sh --help
$ sudo ./bootstrap.sh

 그 다음에 bjam 이란걸 실행시키면 된단다. 간단하네 신선함!

$ sudo ./bjam install

 지루하게 오래걸릴태니 커피를 마시면서 아래 동영상을 좀 보고 있자.


 내 경우에는 넷북인데다...vm으로 우분투를 돌려서 레알 오래걸렸다. 재보진 않았지만 20분은 걸린거 같다능 -_-;; 그리고 중간중간 에러가 좀 나왔지만...됐다는게 중요한거다 >_<.


 이제 6. Link Your Program to a Boost Library 나와있는 소스코드를 따라치고 다이나믹 링크로 컴파일을 해보자.

$ c++ test_boost.cpp -o test_boost -lboost_regex

 다음과 같이 입력해서 라이브러리 패스를 잡아주라능

$ LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}
$ export LD_LIBRARY_PATH


 6.2 Test Your Program에 나와있는 샘플 텍스트를 쳐서 태스트 프로그램을 돌려보자.

$ ./test_boost < jayne.txt
    => will Success Spoil Rock Hunter?

 will Success Spoil Rock Hunter? 라고 결과가 나오면 잘 된거다 >_<.

 ~/.bashrc를 편집해서 환경변수 LD_LIBRARY_PATH를 등록해주면 완전히 끝이다.


2010/04/07 22:29 2010/04/07 22:29
tags :
Computing 2010/04/07 22:29
Powerd by Textcube, designed by criuce
rss