TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Dmitry Esarev
from: Jasen Betts
date: 2003-11-10 06:44:56
subject: how to determine alailable conventional memory using c/asm?

Hi Dmitry.

15-Oct-03 14:24:42, Dmitry Esarev wrote to All


 DE> Hу здорово, уважаемый All!

 DE> using borland c++ 3.1/DOS i need to determine available conv.mem

 DE> i tried to use asm to call INT 12h, but it doesn`t work in modern
 DE> computers (always returning 640Kb

That just tells homw much conventional memory is present.

if you want available use coreleft() if a large data (compact,large,huge)
memory model or
farcoreleft() if small data (tiny,small,medium)

 DE> also tried to use asm  to call dos`s INT 48h, but it always
 DE> returned constant value after a several malloc`s

malloc doesn't use memory owned by dos, malloc uses memory from a pool that
the program claims as its own when it begins execution.

 DE> i also tried to use a standart  DOS.H lib to call
 DE> allocmem(0xFFFF,&seg), but it just returns a largest block
 DE> available(i think it is same as INT 48h

I think so too.

 DE> so i wrote a very DUMB code to get know available conv.mem size in
 DE> bytes it works, and it does what i need, but it so dumb. I know it
 DE> should be a right way to do the thing. Tell me please

there is no "Right way" and it becomes a tricky question once the heap gets
fragmented. borland (turbo C here) provides the coreleft()/farcoreleft()
but I don;t think other compilers do.

if you are only concerned with memory available for malloc() used
coreleft() in all memory models

 DE> //....some code

that could be faster.

include VALUES.H

size_t largest_available_malloc()
 {
 size_t test=0,bit;
 void *p;
 for( bit=1 >1)
   if (NULL==(p=malloc(test+bit))){ test+=bit ; free(p)}
 return test;
 }

it'll return a value of type size_t (unsigned long on the huge memory model unsigned
short on others)

 -=> Bye <=-

---
* Origin: One less than the checksum of "Jasen Betts" (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.