delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/04/06:17:19

Date: Wed, 4 Jun 1997 12:15:13 +0200 (MDT)
Message-Id: <3.0.16.19970605110427.2d5f0684@hem1.passagen.se>
To: djgpp AT delorie DOT com
From: Peter Palotas <blizzar AT hem1 DOT passagen DOT se>
Subject: Locking memory.
Mime-Version: 1.0

I have 8MB of physical RAM installed on my computer (I know, it sux).
I was just thinking then that the following programs would both fail to
allocate that memory, but they don't... Why?


Program 1:
#include <conio.h>
#include <crt0.h>

int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;
char buffer[1024 * 1024 * 20]; // 20MB large buffer

int main(void)
{
        cprintf("hello, world");
        return 0;
}

Program 2:
#include <conio.h>
#include <crt0.h>

int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;

int main(void)
{
        void *buffer = calloc(1024 * 1024, 20;
        if (buffer != NULL)
                cprintf("Memory allocation successful.");
        else
                cprintf("Memory allocation failed.");
        return 0;
}


Both program swap to disk hence using virtual memory. Why is that,
shouldn't the crt0 flags prevent this? Isn't there a way to make sure that
all memory is locked securely?


// Blizzar -- blizzar AT hem1 DOT passagen DOT se -- http://hem1.passagen.se/dnt

****************************************************************************
Don't tell me about the answer, 'cause then another one will come along soon
I don't believe you have the answer, I've got ideas too
But if you got enough naivity, and you got conviction
then the answer is perfect for you!

// Bad Religion - Generator, The Answer
****************************************************************************

- Raw text -


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