Re: Class with only methods - less memory?



redefined.horizons@xxxxxxxxx ha escrito:

I am working on a program that creates hundreds, if not thousands, of
objects in memory. This often causes the program to run out of memory
and shut down.

I am looking for a solution to this. I am curious how much memory is
required from objects that belong to a class that has only method
definitions, and no member variables or other objects included in its
definition.

Object vptr size (probably the same as a native pointer) +
garbage-collection overhead size (probably at least the size of a
native pointer); so at least 8 bytes on a 32-bit machine. There may
also be overhead for the synchronization primitives, or the need to do
synchronization may mean that an Object has to be aligned to a native
cache-line (probably 8 or 16 bytes, possibly more).

On a 32-bit machine, those limitations as well as limitations on what
part of the memory is available to user programs may mean you cannot
have more than about 12 million objects in a single JVM. That would
require 3 GB of memory.

I want to know if I can solve my memory problem by creating an object
that accesses its "data" or member variables off of the hard disk
instead of from RAM. I know this will impose a serious speed or
performance penatly. However, if this will work I can take some steps
to get around the speed problem.

If you have the disk-space, your operating-system will probably allow
you to create a swap-file big enough (3 GB) to allow that JVM to exist
in virtual memory. I just tried it: first I tried running "java
-Xms1100M" and got the error

Error occurred during initialization of VM
Could not reserve enough space for object heap

Then I added a 1-GB swap file and tried the same command; it was
successful. The exact way to add virtual memory depends on your
operating system.

Will I reduce RAM usage by creating hundreds or thousands of objects
from a class that only contains method definitions?

You'll save some memory, but what can you do with a class that
contains only method definitions, and no state? Some ideas to ponder:

1. Use "java.lang.ref.WeakReference" or "java.util.WeakHashMap", or
both, or something similar.

2. Store your data-structure in SQL tables.

3. java.io.RandomAccessFile

4. Store your data in some other Map, but only put entries in the map
for things that are not in their default state.

5. byte[] can store 8 true-false values per byte of memory it uses

Exactly what you choose depends on your application, and you aren't
very specific here.

*David*

.



Relevant Pages

  • Re: Exchange 2003 Private Store Corruption
    ... Once you've pulled the faulty RAM, create the new mailbox store and move ... then you can start working on the problem mailboxes. ... have DIMM's installed in pairs in this server? ... Online Diagnostic Utility says "Correctable Memory Threshold Exceeded" ...
    (microsoft.public.exchange.admin)
  • Re: Can operant conditioning account for all learning?
    ... are not replaying the raw sensory data form that event. ... problems your high level abstractions didn't recognize. ... I would suggest it uses the same amount of memory more ... Most likely the brain doesn't store things in ...
    (comp.ai.philosophy)
  • mm/ hacks -- Generic memory store?
    ... I want to do a memory management hack for generic memory stores. ... "store" for excess memory before OOM. ... RAM swap ... store would be capable of providing compression or encryption. ...
    (Linux-Kernel)
  • Re: Exchange 2003 Private Store Corruption
    ... Information Store First Storage Group: The database page read from ... Online Diagnostic Utility says "Correctable Memory Threshold Exceeded" ... the server back up and running without the faulty memory installed. ...
    (microsoft.public.exchange.admin)
  • Re: Same question - Why use a DataTable in ASP .NET?
    ... When a good deal of memory is consumed, ... For small web applications that don't get ... once you start thinking "high load" ... other words, if you have a primary key, store it in the session, not ...
    (microsoft.public.dotnet.languages.csharp)