At 12:00am -0800 00-11-03, Palm Developer Forum digest wrote:
>Subject: location of const data in memory
>From: "Phil Lamoreaux" <[EMAIL PROTECTED]>
>Date: Thu, 2 Nov 2000 15:47:23 -0500
>X-Message-Number: 178
>
>Does anyone know why const data is placed in the (very limited) heap instead
>of code space?
>
>e.g.:
>
>const char * const s[8] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
>
>takes up 32 bytes of heap.

8 elements * 4 bytes/pointer = 32.

>As far as I can tell, at least the strings are
>not in the heap.
>
>It is worse for non-string data

What's worse about it?

>const long a[5] = { 1, 2, 3, 4, 89000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };

a[5]? You've got 15 elements in your initialization. 15 elements * 4 
bytes/long = 60 bytes.

>takes up 60 bytes of heap.
>
>Is there some other way of doing this short of putting it in a database? It
>aught to just compile as specified (not in dynamic heap space).

As Ben Combee mentioned, PC-relative data created some tricky 
compiler issues. One of the cases he mentioned covers your first 
example above, namely pointers to data; these can't be PC-relative, 
since the correct value for the pointer isn't known until run-time.

On the other hand, your second example should become PC-relative data 
if you use this pragma with a recent version of CodeWarrior:

#pragma pcrelconstdata on

-- Ken

Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-470-9200

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to