473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

PySizeof: almost useful

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,

I'm writing a little module to calculate the size of given objects, I
just need a few little pointers to get the thing into a useful shape.

Code here: http://dev.gentoo.org/~port001/Code/PySizeof/

The points I'm confused about are:

1. My method of determining the malloc() overhead is probably laughable,
what's the correct method?

2. I'm at a loss as how to calculate the size of a long object -- any tips?

3. How much memory do instance, module and instancemethod objects hold?
You'll notice I'm getting the size of most objects internal structures,
what structures' size should I be measuring for such objects?

4. When calculating the size of a dict, if it contains more than the
initial ma_smalltable size (8) should I be subtracting 8 from the len()
number multiplied with the size of a dict entry? See line 73 in pysizeof.py

No doubt there are some other glaring mistakes :)

Many thanks to anyone bored enough to review this code.

- -- Ian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD7S6XefZ4eWAXRGIRAre2AJ4nf//qF/O9B+IhVgdQOj+1rLePZwCaAhvH
7FoGfjjhlm4bH4ZoQY+b+SA=
=C3np
-----END PGP SIGNATURE-----
Feb 11 '06 #1
2 1126
Ian Leitch <po*****@gentoo.org> wrote:
...
2. I'm at a loss as how to calculate the size of a long object -- any tips?
#include "longintrepr.h" (from the Python sources). Then, given a
PyLongObject *l, abs(l->ob_size) is the number of "digits", each taking
SHIFT bits.
Many thanks to anyone bored enough to review this code.


Sorry, I don't have the time, but I hope the above tip can be useful.
Alex
Feb 11 '06 #2
Check the sizeof() method in the mxTools package from eGenix:

<http://www.egenix.com/files/python/mxTools.html>

/Jean Brouwers

Feb 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ken Fine | last post by:
I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the...
7
by: scorpion53061 | last post by:
I was really proud of myself. Having never worked with javascript before I took two scripts - one that did a slideshow but fit the image to the table and one that did not but provided a caption and...
15
by: Steve Richfield | last post by:
To All, First, some of your replies to me have been posted through DevelopersDex, and these are NOT posted on USENET for the world to see. DevelopersDex appears to be trying to hijack USENET,...
3
by: James McGivney | last post by:
In Microsoft Access I make a new Access Project called VipperSQL (Access 2000 file format). I construct a table called Ante with 13 columns. One column called ID is the primary key. Some...
6
by: RDavid | last post by:
Hi all, I know I'll probably get a whole host of opinions, perhaps some vocal and some not, but here goes. I've developed in VB for many years and only now have decided that I need to move...
15
by: Lorenzo Stella | last post by:
Hi all, I haven't experienced functional programming very much, but now I'm trying to learn Haskell and I've learned that: 1) in functional programming LISTS are fundmental; 2) any "cycle" in FP...
1
by: johnbrown105 | last post by:
I think that ideally, ostream_iterator's operator=() should write the delimiter *between* elements and not after them. One way of doing this: Add a default int argument = 0 to...
3
by: copx | last post by:
I saw one here posting the output of a lint tool in a thread, and that made me wonder whether using such tools are still useful. I mean, modern compilers are lint tools themselves, the list of...
7
by: Andy B | last post by:
Just wondering why linq is more useful than datasets? The stuff I do doesn't seem to be too complicated to use linq with it. If I did use linq with it now, I would be doing almost the exact same...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.