Re: Which uses less memory?



bret.wortman@xxxxxxxxx <bret.wortman@xxxxxxxxx> wrote:
I'm not sure if this is as easy a question as I'd like it to be, but
here goes....

I'm working on an application that is very memory intensive, so we're
trying to reduce the memory footprint of classes wherever possible. I
have a need for a class which is able to have a type identifier which
can be examined at run-time to determine whether that class (called
Domain) contains data I care about or not.

I've thought of two ways to implement this:

1. Add a type attribute and set it to a descriptive string.
2. Create marker classes and use multiple inheritance to "attach"
these markers to specific Domains.

Here's the kicker: I need to serialize these Domains and send them to/
from Java code as well as work on them using Python. We're looking to
use Hessian and pyactivemq to handle the Java/Python interfaces.
Which, I guess, leads to the following group of questions:

1. Which method has the smaller footprint within the Python engine?
2. Do these protocols (Hessian and Stomp) preserve the class
information when the class is serialized?

Any input would be most welcome. Thanks!

I don't know the answers to your specific questions but we managed to
1/3 the memory requirement of our app by identifying the class having
the most instances (about 1,000,000 in our case) and adding __slots__
to it!

I'd guess that if you __slot__-ed the Domain class then you'll find
the overhead of a type attribute is minimal (4 bytes per instance I
think).

No idea about Hessian or Stomp (never heard of them!) but classes with
__slot__s are normal classes which would pickle or unpickle.

--
Nick Craig-Wood <nick@xxxxxxxxxxxxxx> -- http://www.craig-wood.com/nick
.



Relevant Pages

  • Re: Code density and performance?
    ... >> quite a bit of research on better locality and packing as ... small and too large for that sort of program. ... similarly for banal programs like 'xterm', which has a memory ... 512B the memory footprint of both 'xterm' and 'ls' above would ...
    (comp.arch)
  • Re: How to reduce memory usage?
    ... If you want a small app revert to assembler;) ... A programs memory footprint is not static. ... footprint of a reasonably well written Delphi gui application is, IMO, ...
    (alt.comp.lang.borland-delphi)
  • Re: Best Linear Equation Solver
    ... memory. ... Hessian to fmincon, but again the main concern is with the Hessian, ... huge that lsqlin would not be an option. ... The best material model of a cat is another, or preferably the same, cat. ...
    (comp.soft-sys.matlab)
  • Re: LISP web hosting
    ... | Do you think clisp would have a smaller memory footprint than cmulisp. ... bulk of the app were compiled). ... Besides, as I said, the real memory ... between GCs using the default 12 MB delta threshold. ...
    (comp.lang.lisp)
  • Re: Object creation overhead
    ... and manually populate 6 of the String variables ... > the private variables, in total about 29 methods for this class. ... * Reduce the number of objects in memory at the same ... and I am trying to get a similar memory footprint ...
    (comp.lang.java)