coreleft - UNIX equivalent ?

coreleft - UNIX equivalent ?

Post by Ilija Hadz » Thu, 01 Jan 1998 04:00:00



Does anyone know what is the UNIX (gcc or g++) equivalent function to
coreleft() which is available on Borland C/C++ compilers for PC ?

coreleft returns the a measure of used memory. I have not seen similar
function on Unix systems. Does anyone know of the one ?

thanks,

I.

 
 
 

coreleft - UNIX equivalent ?

Post by Michael Tobl » Thu, 01 Jan 1998 04:00:00



says...

Quote:> Does anyone know what is the UNIX (gcc or g++) equivalent function to
> coreleft() which is available on Borland C/C++ compilers for PC ?

> coreleft returns the a measure of used memory. I have not seen similar
> function on Unix systems. Does anyone know of the one ?

> thanks,

> I.

Unix uses virtual memory ...
--
_______________________
Blue Skies - Michael T.
_______________________

 
 
 

coreleft - UNIX equivalent ?

Post by Ilija Hadz » Thu, 01 Jan 1998 04:00:00


: Unix uses virtual memory ...
: --
: _______________________
: Blue Skies - Michael T.
: _______________________

I know, but that still does not answer the original question.

I really don't care if the consumed memory is in physical of virtual
address space, I'm just need a system call that will return the amount
of used memory resources.

 
 
 

coreleft - UNIX equivalent ?

Post by Chris Engebrets » Thu, 01 Jan 1998 04:00:00



|> : Unix uses virtual memory ...
|>
|> I know, but that still does not answer the original question.
|>
|> I really don't care if the consumed memory is in physical of virtual
|> address space, I'm just need a system call that will return the amount
|> of used memory resources.

Then have a look at getrusage(), if your system supports it.

By the way, neither the C or the C++ languages provide support for
what you're trying to do.  comp.unix.programmer is the appropriate
newsgroup for UNIX-related coding questions.

Regards,

--
Chris Engebretson - Raytheon STX Corporation | Ph#: (605)594-6829
USGS EROS Data Center, Sioux Falls, SD 57198 | Fax: (605)594-6940

Opinions are not those of  Raytheon Systems Company  or the USGS.

 
 
 

coreleft - UNIX equivalent ?

Post by firewin » Thu, 01 Jan 1998 04:00:00




> : Unix uses virtual memory ...

> I know, but that still does not answer the original question.

> I really don't care if the consumed memory is in physical of virtual
> address space, I'm just need a system call that will return the amount
> of used memory resources.

To which the answer is, of course, You Don't Need to Know That(tm). At any
rate, the ISO C standard does not define any function to do this. You
might want to look through the comp.unix.* heirarchy and see if your
vendor is listed; if so, that would be the appropriate place to post.

[-                               firewind                                   -]

[-          "You're just jealous because the voices talk to -me-."          -]
[-                   Have a good day, and enjoy your C.                     -]
[-          (on a crusade of grumpiness where grumpiness is due)            -]

 
 
 

coreleft - UNIX equivalent ?

Post by Jack Klei » Fri, 02 Jan 1998 04:00:00





> : Unix uses virtual memory ...
> : --
> : _______________________
> : Blue Skies - Michael T.
> : _______________________

> I know, but that still does not answer the original question.

> I really don't care if the consumed memory is in physical of
virtual
> address space, I'm just need a system call that will return
the amount
> of used memory resources.

If you're going to post silly off-topic questions about
translating a non-standard function from one compiler/operating
system to another non-standard function on another non-standard
operating system, at least get the details right.

Borland C ___NEVER___ provided a function to tell you how much
memory was in use.  Nope.  Absolutely not.  No way.

The very name "coreleft" conjures in the mind the image of how
much core is still left to be used, not how much is already
used.

And sure enough, here is the text copied right out of the online
help for the DOS IDE of Borland 3.1, and pasted here:

coreleft returns a measure of RAM memory not in use.

BTW, 3.1 is the last version it appeared in.

Jack

 
 
 

coreleft - UNIX equivalent ?

Post by Pete Becke » Fri, 02 Jan 1998 04:00:00



> If you're going to post silly off-topic questions about
> translating a non-standard function from one compiler/operating
> system to another non-standard function on another non-standard
> operating system, at least get the details right.

Sigh. The question "how can I find out how much memory is still
available for use by my program" is clearly not off topic here. Of
course, the answer is, "you can't". But that's worlds different from
flaming someone for asking the question. Please, folks, pay attention to
what's being asked: just because you see the name of a compiler and the
name of a non-standard function, that doesn't automatically make the
question off topic. A little more civility would go a long way toward
making this newsgroup more useful.

Quote:

> Borland C ___NEVER___ provided a function to tell you how much
> memory was in use.  Nope.  Absolutely not.  No way.

> The very name "coreleft" conjures in the mind the image of how
> much core is still left to be used, not how much is already
> used.

> And sure enough, here is the text copied right out of the online
> help for the DOS IDE of Borland 3.1, and pasted here:

> coreleft returns a measure of RAM memory not in use.

> BTW, 3.1 is the last version it appeared in.

That's odd, my copy of 5.2 has coreleft(). <g> It's only available when
you're compiling 16-bit non-Windows programs, though.
        -- Pete
 
 
 

coreleft - UNIX equivalent ?

Post by Jack Klei » Sat, 03 Jan 1998 04:00:00


In response to those who responded to me (Pete Becker and Terry
R. McConnell:

1.  That wasn't a flame.  I generate __much__ more heat when I
flame.

2.  The definition in my post was literally the first line of
the description from the DOS 3.1 IDE.  It does go on to give
additional information, but this was sufficient to indicate that
the function would _not_ do this:

Quote:> I really don't care if the consumed memory is in physical of
virtual
> address space, I'm just need a system call that will return
the amount
> of used memory resources.

Interestingly enough, the function is still available in 4.52
(latest I have) but is completely absent from the library
reference manual for 4.0 (last printed documentation I have).

Jack

 
 
 

coreleft - UNIX equivalent ?

Post by Pete Becke » Sat, 03 Jan 1998 04:00:00



> In response to those who responded to me (Pete Becker and Terry
> R. McConnell:

> 1.  That wasn't a flame.  I generate __much__ more heat when I
> flame.

I've reread both messages that you mention, and neither one uses the
word "flame". However:

Quote:> If you're going to post silly off-topic questions about
> translating a non-standard function from one compiler/operating
> system to another non-standard function on another non-standard
> operating system, at least get the details right.

That's a flame. Claiming that you could have been much nastier doesn't
change that.
 
 
 

coreleft - UNIX equivalent ?

Post by F. Paul Menar » Sat, 03 Jan 1998 04:00:00


I'm not sure if this is equal, but there is a function 'mallinfo()' which
will report on the USED
memory total for a program. This used memory is a result of total malloc()
calls. Of course I only have access
to SCO UNIX

FPM


>Does anyone know what is the UNIX (gcc or g++) equivalent function to
>coreleft() which is available on Borland C/C++ compilers for PC ?

>coreleft returns the a measure of used memory. I have not seen similar
>function on Unix systems. Does anyone know of the one ?

>thanks,

>I.

 
 
 

coreleft - UNIX equivalent ?

Post by J. Kan » Mon, 05 Jan 1998 04:00:00


|>  > coreleft returns a measure of RAM memory not in use.
|>  >
|>  > BTW, 3.1 is the last version it appeared in.
|>  
|>  That's odd, my copy of 5.2 has coreleft(). <g> It's only available when
|>  you're compiling 16-bit non-Windows programs, though.

Could that be because it doesn't make sense in Windows, any more than it
does under Unix.

I don't know about Windows, but Unix is a multi-user, multi-process
system.  Which means that the amount of core left (virtual or real) will
vary in time independantly of what your program does, and that any
value that coreleft returns would be outdated before you could use it.

--

GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique oriente objet --
              -- Beratung in objektorientierter Datenverarbeitung

 
 
 

coreleft - UNIX equivalent ?

Post by Phli » Mon, 05 Jan 1998 04:00:00


Quote:>I don't know about Windows, but Unix is a multi-user, multi-process
>system.  Which means that the amount of core left (virtual or real) will
>vary in time independantly of what your program does, and that any
>value that coreleft returns would be outdated before you could use it.

All flavors of Windows, plus MAC, AmigaDOS, etc., are multi-process. It
appears 'coreleft' would only ever have been of any use in a monolith like
DOS, or even more obsolete systems like the Commodore 64 (or Multix?) where
the CPU multi-processed by partitioning memory into static areas, one per
program, without regard to how much memory any one program needed.
 
 
 

coreleft - UNIX equivalent ?

Post by Phil Howa » Fri, 09 Jan 1998 04:00:00




| : Unix uses virtual memory ...
| : --
| : _______________________
| : Blue Skies - Michael T.
| : _______________________
|
| I know, but that still does not answer the original question.
|
| I really don't care if the consumed memory is in physical of virtual
| address space, I'm just need a system call that will return the amount
| of used memory resources.

The coreleft function has to know how much is used and how much total is
available.  In DOS that information is available.

In virtual memory, there are TWO levels of memory allocation taking place
on most systems (all UNIX systems AFAIK).  Some amount of virtual space
is constructed in the page/segmentations tables for that process.  Not all
of it is allocated.  Program malloc() calls take from this space until it
is gone, and then they get more.  The function there is usually sbrk().

Just how much can you get with sbrk()?  If your address size is 32-bits
perhaps as much as 4gig.  But that memory also may need to be represented
in the swap space, or at least in the combination of swap and real RAM.
And this is a common pool being accessed by other virtual processes.
That space MIGHT be available right now, but not in a few seconds from
now because some other process took it.

And the information might simply be unavailable, and rightly so in secure
systems.  In order to find out how much space is available, try to get it
and see if you can get it.

The answer is, virtual memory makes this a situation where there simply is
not a direct answer to "how much core is left for my program".

--
 --    *-----------------------------*       Phil Howard KA9WGN        *    --
  --   | Inturnet, Inc.              |  Engineering Operations Manager |   --
   --  | Business Internet Solutions |        eng at intur.net         |  --
    -- *-----------------------------*       philh at intur.net        * --

 
 
 

coreleft - UNIX equivalent ?

Post by Kaz Kylhe » Sat, 10 Jan 1998 04:00:00





>: Unix uses virtual memory ...
>: --
>: _______________________
>: Blue Skies - Michael T.
>: _______________________

>I know, but that still does not answer the original question.

>I really don't care if the consumed memory is in physical of virtual
>address space, I'm just need a system call that will return the amount
>of used memory resources.

In some systems like Linux, the superuser can add virtual memory on
the fly by creating more swap partitions or swap files even as the
operating system is running. Conversely, the superuser can remove
swap areas.

Moreover, other processes are allocating and freeing storage concurrently
to the execution of your process.

Hence any number you obtain about the present state of affairs will
likely be hopelessly out of date by the time you use it.

In the olden days of 8 bit micros and early PC's, it was important for
applications to report available memory and disk space to the user.  For one
thing, the systems were mono-tasking; once the application grabbed control of
the computer, there was no other way to interact with the computer other than
through that application. Hence applications had to incorporate some system
administration functions such as file management, and reporting on disk space
and memory usage.

In a modern operating system, the user can determine and manage the available
resources independently of the application using the system's specific tools
for that purpose. Hence you  no longer have to incorporate low resource
``alarms'' or ``memory remaining'' displays; just worry about writing
the application so that it consumes as little memory as it needs to
get the job done.

 
 
 

coreleft - UNIX equivalent ?

Post by Will Ro » Sat, 10 Jan 1998 04:00:00




: | : Unix uses virtual memory ...
: | : --
: | : _______________________
: | : Blue Skies - Michael T.
: | : _______________________
: |
: | I know, but that still does not answer the original question.
: |
: | I really don't care if the consumed memory is in physical of virtual
: | address space, I'm just need a system call that will return the amount
: | of used memory resources.

[...]
: And the information might simply be unavailable, and rightly so in secure
: systems.  In order to find out how much space is available, try to get it
: and see if you can get it.

And also in unsecure systems... OS/2 is not Unix (suprise!) but allocated
memory is in many circumstances (not all, just to add to the fun) backed
by the swap file; you're out of memory when the swap file runs out of
disk.  There isn't a system call that will give you that value.

In most VM systems, the trick is to let the VM do the VMing - ask it for
the memory you need, and if it gives it to you, you've got it.

Will