Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Dynamic Memory allocation

Reply
Thread Tools

Dynamic Memory allocation

 
 
Keith Thompson
Guest
Posts: n/a
 
      05-14-2008
Szabolcs Borsanyi <(E-Mail Removed)-heidelberg.de> writes:
>> smarty wrote:
>>
>> Just malloc what you need and check the returned value. If it is
>> NULL that memory is not available.
>>

> 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>


Can you please format your text to a maximum of, say, 72 columns?
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.

If you're on a Unix-like system, you can filter your paragraphs
through something like "fmt -72" or "fmt -70", or perhaps your
text editor or newsreader has a "fill" command.

Thanks.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Szabolcs Borsanyi
Guest
Posts: n/a
 
      05-14-2008
>> Can you please format your text to a maximum of, say, 72 columns?
> 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.


Sorry, I forgot about that.
Apologies
Szabolcs
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      05-14-2008
Szabolcs Borsanyi <(E-Mail Removed)-heidelberg.de> writes:
>>> Can you please format your text to a maximum of, say, 72 columns?

>> 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.

>
> Sorry, I forgot about that.
> Apologies
> Szabolcs


You also forgot to leave the attribution line in place. (I'm a bit
sensitive about that, since one poster here removes attribution lines
deliberately.)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
sandy
Guest
Posts: n/a
 
      05-14-2008
On May 14, 9:35 pm, CBFalconer <(E-Mail Removed)> wrote:
> smarty wrote:
>
> ... snip ...
>
> > 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?

>
> 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.
>

What do you mean by "most systems use virtual memory, so there is no
practical limit" ?
Even virtual memory has a limit ? Will it not be restricted by the
size of your address space, PRACTICALLY ?
And don't you think, your heap will be full and will return a NULL
over a period of continuous memory allocations.

Kindly correct me if I am wrong somewhere.

Regards,
SandeepKsinha.
> --
> [mail]: Chuck F (cbfalconer at maineline dot net)
> [page]: <http://cbfalconer.home.att.net>
> Try the download section.
>
> ** Posted fromhttp://www.teranews.com**


 
Reply With Quote
 
sandy
Guest
Posts: n/a
 
      05-15-2008
On May 15, 3:13 am, "Malcolm McLean" <(E-Mail Removed)> wrote:
> "sandy" <(E-Mail Removed)> wrote> What do you mean by "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.
>
> --


I am not arguing, but not convinced completely.
When you are talking about today's machine memory allocation
policies,
then why would you consider the memory hoppers ( Applications ) of
1990's.

I think, the demand and supply should be in today's context and in
sync.

> Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm


Regards,
SandeepKsinha.
 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      05-15-2008
smarty wrote:
> On May 13, 8:59 pm, Keith Thompson <(E-Mail Removed)> wrote:
>> smarty <(E-Mail Removed)> writes:
>>> 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".

>
> 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 once heard of one implementation to find out how much memory could be
malloced, they called malloc with a HUGE number and checked for error. They
released any memory that was actually allocated and kept chaning the number
til they found the largest amount they could allocate.

I was always suspicious of this method especially with page swapping and
such and the OS would be paging things in and out of memory for all the
memory allocations.

One method may be to simply determine how much memory you are going to need
on the outside, try to malloc it. If it is malloced release it and
continue. This may adversely effect memory management with memory holes and
such, I don't know. It depends a lot of your OS and how it handles dynamic
memory allocation requests.


--
Jim Langston
(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An idea for heap allocation at near stack allocation speed Bjarke Hammersholt Roune C++ 14 03-06-2011 08:07 AM
static memory allocation versus dynamic memory allocation Ken C Programming 24 11-30-2006 12:37 AM
What is the difference between dynamic memory allocation,and stack allocation ? chris C++ 6 10-28-2005 05:27 AM
Dynamic memory allocation and memory leak... s.subbarayan C Programming 10 03-22-2005 02:48 PM
structs and dynamic memory allocation Roman Hartmann C Programming 11 11-05-2003 07:53 AM



Advertisments