At 07:05 AM 7/13/04 -0700, you wrote:
>yes there is a problem with yahoo groups..
Well, I consider it a feature. That alone keeps the size of messages to a
manageable level and stops the current crop of worms dead in their
tracks. But I'm heading off topic.
>#include <stdlib.h>
>
>/* Mapped to Read-Only Data Section (.rodata) */
>
>const char Text[] =
> "This is a dummy text which will be loaded into the
>.rodata section.";
Keil uses GNU so unless they've done something odd in the linker file this
will be in flash along with all other const data.
> m = malloc(1024); /* Allocate Memory on Heap */
> if (m == NULL) return (1);
(A)
And this will be in RAM (SRAM if you want to get particular). The heap
location is set by the startup (crt0.s) usually using information supplied
by the link file at link time.
> p = m;
> t = (char *)&Text[0];
> while (*t) {
> *p++ = *t++; /* Copy Text to Heap
>*/
> }
> *p = 0; /* Terminate String */
(B)
This copies from flash to ram.
> free(m); /* Free Allocated Memory */
(C)
and notifies the heap manager that the area can be re-used in a subsequent
malloc call.
To do this with malloc allocating from flash instead of SRAM then you would
have to rewrite malloc for step A so that it would use the IAP routines to
set up the appropriate structures in flash (and observe the flash
limitations). The in step B you could not use a simple assignment but
would again need to call the IAP routines to copy to flash and finally in
step C you would have to mark the area as unused and at some point do some
sort of garbage collection to actually erase unused areas (while preserving
used areas) so they could be reused in a subsequent malloc call. As I said
more like a file system than heap management.
Robert
" 'Freedom' has no meaning of itself. There are always restrictions,
be they legal, genetic, or physical. If you don't believe me, try to
chew a radio signal. "
Kelvin Throop, IIIMessage
Re: [lpc2000] memory allocation..
2004-07-13 by Robert Adsett
Attachments
- No local attachments were found for this message.