Silly String / memory Question

Started by
2 comments, last by Drazgal 21 years, 8 months ago
When I pass a string into a function as an argument such as, Functionction("String"); Is this string handled in memory? Deleted when it is over (assuming it is being passed in as a char*) or does it create a memmory leak? I assume its cleared up for me automatically but I just want to make sure. Ballistic Programs
Advertisement
Actually that string is static...the compiler creates space in your data segment (I think)...but it''s neither created or destroyed, it just exists...

so, in your function call...the compiler will push the address of that static variable on the stack, and call your function. The stack cleanup is handled for you, and so no memory leaks occur...

this wasn''t a stupid a question...I didn''t figure it out, till I started looking at the assembly...which I suggest you do
People fear what they don''t understand, hate what they can''t conquer!
Thanks for the quick reply, as for assembly, its on my list, just as soon as I finsh this IDE for MASM.

Ballistic Programs
thats behavior is compiler dependent.

This topic is closed to new replies.

Advertisement