Skip to main content
gamedev.net
🔒 Locked

Silly String / memory Question

Started by Drazgal Jul 24, 2002 at 1:29 PM 2 replies 350+ views
Original Post
Drazgal
Drazgal
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
Bashar
Bashar
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!
Drazgal
Drazgal
Thanks for the quick reply, as for assembly, its on my list, just as soon as I finsh this IDE for MASM.

Ballistic Programs
EvilCrap
EvilCrap
thats behavior is compiler dependent.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.