GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Jun-2009, 09:19
aska aska is offline
New Member
 
Join Date: Jul 2008
Posts: 5
aska is on a distinguished road
Post

Determining memory size in C?


i have a little code for determing memory size this my code:
CPP / C++ / C Code:

/*   using interupt 12H  BIOS)              */
#include<stdio.h>
#include<bios.h>
int main(void)
 {
  printf("memory size %d kbite\n", biosmemory());
  return 0;
 }
by compiling i have error:Cannot open include file: 'bios.h': No such file or directory..so where i can find thi file if needed or how i can solve it by another way?
Last edited by LuciWiz : 01-Jun-2009 at 09:31. Reason: Please insert your C code between [cpp] & [/cpp] tags
  #2  
Old 01-Jun-2009, 10:29
nordtorp nordtorp is offline
New Member
 
Join Date: Jun 2009
Posts: 1
nordtorp is on a distinguished road

Re: memory size in C?


Hello aska,

I just Googled around and came across your thread. The biosmemory is only compatible with DOS and Windows 3.x.

Look at this page for more information: http://www.digitalmars.com/rtl/bios.html#_bios_memsize

As for any solution for your problem, I don't really know.

What memory are you going to read? System memory (RAM) or some cache of some sort?
  #3  
Old 01-Jun-2009, 11:00
aska aska is offline
New Member
 
Join Date: Jul 2008
Posts: 5
aska is on a distinguished road

Re: memory size in C?


I'm going to read system memory (RAM).
  #4  
Old 01-Jun-2009, 14:55
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: memory size in C?


Quote:
Originally Posted by aska
I'm going to read system memory (RAM).
Do you mean to read the amount of physical memory present in your system?

There are no standard C or C++ library functions that deal with hardware considerations (ram, video display, etc.)

There may be operating-system dependent functions available with your compiler.

For example, on my Windows xp platform with Microsoft and Borland compilers I can use the following, based on an example from msdn:

CPP / C++ / C Code:
/*  
    From the example at
        [url]http://msdn.microsoft.com/en-us/library/aa366589.aspx[/url]

    davekw7x

*/

#include <windows.h>
#include <stdio.h>

int main()
{
    MEMORYSTATUSEX statex;

    statex.dwLength = sizeof (statex);
    GlobalMemoryStatusEx (&statex);

    printf("Memory size = %7I64d Bytes\n", statex.ullTotalPhys/1024);
    return 0;
}

If your workstation has one GByte of memory installed, you can expect to see something like:
Code:
Memory size = 1048048 kBytes

If you are running Linux, you can get the information from /proc/meminfo.

With my various Linux workstations, I can just open /proc/meminfo as a file and read a line at a time into a buffer until I see the line that begins with "MemTotal:"

Then I use sscanf to read the second item into an unsigned long variable.

Regards,

Dave

Footnote: The "/proc/meminfo" stuff also works for me with GNU gcc on my Windows/Cygwin workstation.

If you have some compiler other than GNU or a fairly recent Microsoft or Borland compiler or if you are using some other operating system there may be (or, maybe not) similar (or dissimilar) functions. In other words, any time you need non-standard functions for your task: YMMV (Your Mileage May Vary).
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A Complete Guide to SD Memory Cards haulkook Computer Hardware Forum 0 02-Jul-2008 00:27
A Few Tips on Buying Good Memory Cards and other Hi-Tech Electronic Accessories haulkook Computer Hardware Forum 0 02-Jun-2008 04:53
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 19:35
Having a problem Chuckles Computer Hardware Forum 19 13-Sep-2004 13:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:24.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.