getting memory information under NT

dan_knierim at dan_knierim at
Mon Jun 28 16:02:49 EDT 1999

In article <375E88A2.68C1F118 at>,
  Eric Renouf <erenouf at> wrote:
> Does anyone know of an easy way to get the the total physical memory
> and/or available memory on an NT system using Python 1.5.2?  Is there
> module that has functions for things like this already?
> Thanks,
> Eric Renouf
I earlier posted an incorrect response to your inquiry, sorry.

A better answer is: look at Sam Rushing's windll and structob modules,
part of the DynWin software available from the download site,
or from  These use Mr. Rushing's
calldll and npstruct utilities, which are also available from those

The downloads include some very helpful demo code, but the demos I
got seem not quite in sync with the release of DynWin that I have.  In
particular the module has an example of how to call the
Windows function 'GlobalMemoryStatus' as follows (edited for brevity):

# -*- Mode: Python; tab-width: 4 -*-
# Author: Sam Rushing <rushing at>

import windll, structob

kernel32 = windll.module ('kernel32')

memstat = structob.Oracle ('memory status structure', 'Nllllllll',
                           ('Length', 'MemoryLoad', 'TotalPhys',
                            'AvailPhys', 'TotalPageFile',
                            'AvailPageFile', 'TotalVirtual',
                            'AvailVirtual') )

def global_memory_status():
	buffer = windll.membuf (memstat.size)
	result = kernel32.GlobalMemoryStatus (buffer.address())
	dict, size = memstat.unpack (
	memstat.describe (dict)

----------- end of code fragment

I haven't checked the following with the author or any Python wizes, but
I'll explain what I think based on my experiments and reading bits of
the code.

The second parameter in the call to structob.Oracle, 'Nllllllll', is a
format code, and the first character 'N' is supposed to indicate whether
the data structure uses big-endian or little-endian byte order.  However
this value must be for a different version of npstruct, because the
release I have of (which interprets the format code) expects
either an 'L' (for little-endian) or a 'B' (for big-endian) as the first
character.  After I replaced the 'N' with 'L', the assignment to memstat
looks like

memstat = structob.Oracle ( 'memory status structure', 'Lllllllll',

The demo now runs fine.

The Win32 extensions from Mark Hammond (also available from in the win32all download) provide an interface to the
Performance Monitor counters, in modules win32pdh*.py.  This gives
access to several detailed measures related to memory usage (the same
ones available through the NT Performance Monitor admin tool).

Good luck,
Dan K.

Corporation: n. An ingenious device for obtaining individual profit
without individual responsibility. -- Ambrose Bierce

Sent via
Share what you know. Learn what you don't.

More information about the Python-list mailing list