At 12:18 PM 3/10/99 -0500, you wrote:
>> char s1[]= "Hello";   // array of characters
>> CharPtr  s2;      // pointer to a string
>> char s3[20];    // array of 20 caharacters
>> CharPtr s4[10];    // array of 10 pointers
>> int i;    // integer
>> int j[10];    // array of 10 integers
>>
>> s2 = "Goodbye";
>> i = 15;
>>
>
>      In your example, s, s2, s3, s4, i, and j are all on the stack (total
>usage 92 bytes, assuming ints are 2 bytes), and where that constant string
>lives depends on your compiler settings.  I'll let the compiler jockeys
>figure out where that one goes - it's probably in your global data, which I
>think is on the heap, but don't quote me.  If you wanted to allocate one of
>your arrays on the heap, you'd declare it as a pointer and use MemPtrNew to
>allocate it.
>

I'm no compiler jockey, but the declaration for s1 will allocate 6 bytes on
the stack, and initialize it to "Hello\0".  This is because you declared it
as a non-const array.

const char s1[] = "Hello";

would have generated 6 bytes for the string "Hello" and 4 bytes for the
pointers (s1 and sP) to these strings.  

Hope this helps.

Regards,
Greg

Greg Winton
Bachmann Software and Services, LLC
mailto:[EMAIL PROTECTED]
http://www.bachmannsoftware.com
Software Development for Handheld & Mobile Computing, Windows and the Internet
Home of Bachmann Print Manager, the only graphical printing solution for
the Palm Computing Platform

Reply via email to