View memory allocation

OP #1171826
Rate this post
• ▲ useful
▼ not useful
hi,


I have a C source code .I have created an elf image using the source
code along with startup code and linkerscript. I want to view the memory
partion ie, length of code segment , data segment stack and heap.Is
there any methode to view the allocated memory (ie, segment based
addresses)?.

Is there any way to monitor the heap allocation , ( to avoid the stack
heap overlapping)?

regards
thejus
#1171827
Rate this post
• ▲ useful
▼ not useful
The linker can output a map file to show memory organisation of your
code with teh following option:

-Map <mapfile>

With respect to heap monitoring. The sbrk()/sbrk_r() syscall function is
ultimately how the system aquired heap. You have te implement this
yourself (or use one of the examples), you can add code here to perform
monitoring operations, but it is normally written to be bounded to a
defined memory region. Of greater concern would be stack overflow, since
that is more difficult to guard against. A common approach is to
pre-fill the stack segment with a known and repeated value or sequence
of values, then to determine stack usage, scan the segment to test for
the 'high warter mark'.

Clifford
OP #1171828
Rate this post
• ▲ useful
▼ not useful
hi Clifford,

Actually i am using so many pointers (some size up to 8mb). So if there
is a way to view the heap allocation we can judge whether heap over
writes the stack. am i right?

What is the difference between hw stack and sw stack.? how can we know
exactly how much space is required for stack (in hw).

regards
thejus



Clifford Slocombe wrote:
> The linker can output a map file to show memory organisation of your
> code with teh following option:
>
> -Map <mapfile>
>
> With respect to heap monitoring. The sbrk()/sbrk_r() syscall function is
> ultimately how the system aquired heap. You have te implement this
> yourself (or use one of the examples), you can add code here to perform
> monitoring operations, but it is normally written to be bounded to a
> defined memory region. Of greater concern would be stack overflow, since
> that is more difficult to guard against. A common approach is to
> pre-fill the stack segment with a known and repeated value or sequence
> of values, then to determine stack usage, scan the segment to test for
> the 'high warter mark'.
>
> Clifford

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.