S
smarty
how can I find the memory allocated dynamically? is there any
possibility of finding it?
possibility of finding it?
smarty said:how can I find the memory allocated dynamically? is there any
possibility of finding it?
smarty said:how can I find the memory allocated dynamically? is there any
possibility of finding it?
unsigned char *ptr;
ptr = malloc(100); /* grab 100 bytes of memory */
printf("%p\n", ptr); /* print out the location of the memory in
human-readable format */
smarty said:how can I find the memory allocated dynamically? is there any
possibility of finding it?
smarty said:how can I find the memory allocated dynamically? is there any
possibility of finding it?
how can I find the memory allocated dynamically? is there any
possibility of finding it?
Your question is unclear; I can think of several things you might be
asking. Do you want to find out *how much* memory has been allocated
dynamically? Do you want to determine the address of a particular
chunk of dynamically allocated memory? Or of all dynamically
allocated memory? Just within your program or elsewhere?
Please post again, stating your question more clearly, and tell us
*why* you wnat to do whatever it is you're trying to do. It's very
likely that the answer is going to be either "You can't do it", or
"You can't do it portably", or "You allocated it, you have to keep
track of it".
smarty said:I came across a situation where i have to find the availability of
free dynamic memory that can be "malloc"ed. May be this is what a
memory manager does when malloc is called. Can i implement this as a
program? How?
I would not do that. The standard has no guarantee for a correctsmarty said:Just malloc what you need and check the returned value. If it is
NULL that memory is not available.
Szabolcs Borsanyi said:I would not do that. The standard has no guarantee for a correct
program to run,
just that if it runs, then the output is correct.
<off>
Modern systems (like linux) tend to be overoptimistic in the malloc
call and they
check only the availability of the addressing space, but not the
physical
memory or swap space. On the first write the kernel will think about
how to
acquire the memory, and kill someone if it does not succeed otherwise.
As for me, I usually ask the system of the total memory (there are
system calls
on most platforms that return this information) and my programs assume
that
all (or 80%) is available. And systems with lazy allocation take that
quite well.
</off>
It appears that you're writing lines up to about 81 columns,
and something somewhere is shortening them to about 70 columns.
The result is the alternating long and short lines seen above,
which are difficult to read.
Szabolcs Borsanyi said:Sorry, I forgot about that.
Apologies
Szabolcs
What do you mean by "most systems use virtual memory, so there is nosmarty wrote:
... snip ...
Just malloc what you need and check the returned value. If it is
NULL that memory is not available.
Some non-standard systems used to have routines to return the
amount available. Today, most systems use virtual memory, so there
is no practical limit.
He means the amount of memory available is so large in relation to the
amount that is likely to be requested that there will never be a problem.
He's right in so far as if you run typical 1990s programs like
wordprocessors or spreadsheets on 2008 machines, the memory take is tiny.
However people are always finding new things to do with computers, like
embedding little video clips in personal webpages, and so the resources tend
to be used.
--
Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm
smarty said:I came across a situation where i have to find the availability of
free dynamic memory that can be "malloc"ed. May be this is what a
memory manager does when malloc is called. Can i implement this as a
program? How?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.