467,905 Members | 1,725 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,905 developers. It's quick & easy.

Is dynamic Memory allocation- most effective one?

Diff b/w Static and Dynamic Memory allocations?

which var(Static/dynamic) is to be used to create a application for the embedded Environment?

which one is most effective one for a embedded linux environment ?
Jul 27 '07 #1
  • viewed: 1508
Share:
5 Replies
Expert 8TB
Diff b/w Static and Dynamic Memory allocations?

which var(Static/dynamic) is to be used to create a application for the embedded Environment?

which one is most effective one for a embedded linux environment ?
If the device is able to run Linux it is big enough to support simple dynamic
memory (malloc/free). There's no need to worry about it.

kind regards,

Jos
Jul 27 '07 #2
thanks Jos

i want know about,
how the calloc/malloc Vs static var works with memory?
how the processes using stack/heap memory ?

can you explain me on this plz,

thanks
Balaji
Jul 27 '07 #3
Expert 8TB
thanks Jos

i want know about,
how the calloc/malloc Vs static var works with memory?
how the processes using stack/heap memory ?

can you explain me on this plz,

thanks
Balaji
There's nothing magic about the two: static memory is already present when
your process starts, i.e. for every single global variable there's memory available
for it already. Dynamic memory management simply asks chunks/pages of
memory from the OS and hands it out to your process piecemeal when malloc
requests for it.

kind regards,

Jos
Jul 27 '07 #4
There's nothing magic about the two: static memory is already present when
your process starts, i.e. for every single global variable there's memory available
for it already. Dynamic memory management simply asks chunks/pages of
memory from the OS and hands it out to your process piecemeal when malloc
requests for it.

kind regards,

Jos

Embedded linux in the sense core have own fixed memory for montavista like linux and it is having some minimum size of memory only.also i want the processing time for the application is less i.e., faster response.
Here application means, which we are creating with some c code ( that have code like mem allocation, some more req operations and freeing it at last).

I want to know some details about internal things, like how memory allocation happening with memory for the static and dynamic memory allocations during which (build /run) time ?

which process will take time to allocate mem either static or dynamic?
I thought dynamic memory will take more time than static.. And it will do some more internal processes.. is it? can plz you explain me on this?
Jul 29 '07 #5
Expert 8TB
I think you're overcomplicating matters here: after your process has been loaded
into memory, your initialized global variables are ready to be used. The other,
noninitialized global variables end up in a block of memory for which all bits are
set to zero.

Next a 'heap' is constructed: first the 'brk()' or 'sbrk()' system call allots a block
of memory to your process. This will be the initial heap. All the malloc'd memory
comes from this heap and is returned to this heap when free'd. Note that nothing
moves in there; i.e. just a few pointer values are fiddled with.

When more memory is needed for the heap, brk() or sbrk() is called again; some
heap management schemes are clever enough to return memory to the OS
again, again using these same system calls (check the man pages).

Basically you refer to that heap memory (dynamic memory) through pointers
just because you don't know in advance *where* in memory your allocated
memory will be present.

There are no other processes involved for your process' heap management,
in fact that management is part of your process, it was (dynamically?) linked
in to your process.

kind regards,

Jos
Jul 29 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Tom | last post: by
6 posts views Thread by Sandeep Chikkerur | last post: by
13 posts views Thread by xian_hong2046 | last post: by
11 posts views Thread by toton | last post: by
14 posts views Thread by vivek | last post: by
10 posts views Thread by swornavidhya.mahadevan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.