Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obtaining physical memory size from c library



Or he could just use the correct sysctl instead of the old one.

<sys/sysctl.h>:
#define HW_MEMSIZE 24 /* uint64_t: physical ram size */


-- Terry

On Oct 5, 2005, at 2:09 PM, Dave Zarzycki wrote:\
Try this:

int memmib[2] = { CTL_HW, HW_PHYSMEM };
uint64_t mem = 0;
size_t memsz = sizeof(mem);

if (sysctl(memmib, 2, &mem, &memsz, NULL, 0) == -1) {
syslog(LOG_WARNING, "sysctl(\"%s\"): %m", "hw.physmem");
} else {
/* The following assignment of mem to itself if the size
* of data returned is 32 bits instead of 64 is a clever
* C trick to move the 32 bits on big endian systems to
* the least significant bytes of the 64 mem variable.
*
* On little endian systems, this is effectively a no-op.
*/
if (memsz == 4)
mem = *(uint32_t *)&mem;
}


On Oct 5, 2005, at 2:02 PM, Daniel Quinlan wrote:


I would like to get the physical memory size on a Mac with some call to a c routine, on both Panther and TIger. I have been
using sysctl with HW_PHYSMEM, but this returns a size in bytes in a 4 byte integer, which doesn't work well with 8 Gbytes
of memory. I think there's some function named Gestalt, but I haven't found documentation nor the link line necessary
to use this.


Any suggestions?
Thanks,
-- danq



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/zarzycki% 40apple.com


This email sent to email@hidden


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/tlambert% 40apple.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Unix-porting mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/unix-porting/email@hidden

This email sent to email@hidden
References: 
 >Obtaining physical memory size from c library (From: Daniel Quinlan <email@hidden>)
 >Re: Obtaining physical memory size from c library (From: Dave Zarzycki <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.