www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/24/20:14:19

Comments: Authenticated sender is <mert0407 AT sable DOT ox DOT ac DOT uk>
From: "George Foot" <george DOT foot AT merton DOT oxford DOT ac DOT uk>
To: "Cludio Andr Heckler" <heckler AT mat DOT ufrgs DOT br>
Date: Tue, 25 Aug 1998 01:03:45 +0000
MIME-Version: 1.0
Subject: Re: Need to know free memory
Reply-to: george DOT foot AT merton DOT oxford DOT ac DOT uk
CC: djgpp AT delorie DOT com
Message-Id: <E0zB6bo-0005zZ-00@sable.ox.ac.uk>

On 24 Aug 98 at 9:32, Cludio Andr Heckler wrote:

> 	Problem: the FAQ says, at 15.2 that "When you call free, 
> DJGPP library doesn't return memory to the system, it just adds it
> to its internal pool of free pages. So, from the system point of
> view, these pages are not 'free'."

Thank you for reading the FAQ before posting.

> 	This way, when I free memory, I don't see any change in
> the value returned by _go32_dpmi_get_free_memory_information.
> So, how can I calculate the REAL amount of free memory that I
> can use ?

It's hard to judge that anyway; just because 
_go32_dpmi_get_free_memory_information says there's a certain amount 
of free memory, it doesn't mean that there really is that much that 
you can use.

What you're trying to do isn't simple, and is prone to error.  It's
better to think of another way to approach this.  For example, you
could try to allocate a certain amount of memory on startup; if it
succeeds, let your program choose from those already-allocated blocks
when it allocates.  If you run out of free blocks, allocate some
more.  It's verging on creating your own malloc/free routines though.

Another point:  You said you wanted to allocate a lot of memory 
without swapping.  If you absolutely don't want to swap (i.e. you'd 
rather the allocations failed) then you can disable virtual memory 
support by using the crt0 startup flag `_CRT0_FLAG_LOCK_MEMORY'.  Put 
in one of your .c files:

    #include <crt0.h>
    
    int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;

See crt0.h itself for more details.  In this state, if not enough 
physical memory is available, allocations will fail.

If only some of your allocations mustn't fail, you can write a 
wrapper to `malloc' like this:

    #include <stdlib.h>
    #include <dpmi.h>
    
    void *malloc_and_lock (size_t size) {
        void *ret = malloc (size);
        if (!ret) return NULL;
        if (_go32_dpmi_lock_data (ret, size)) {
            free (ret);
            return NULL;
        }
        return ret;
    }

Call this like `malloc' if the allocation must be locked.  If you use 
`realloc' on the resulting block it may not be locked any more; 
you'll need to wrap that in a similar way if this is a problem.  You 
can `free' the block as usual.

> 	PS.: How do I subscribe to the mailling list ?

Send a message to listserv AT delorie DOT com with just the word "help" in 
the body of the message.  It will reply with full subscription 
instructions.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019