1

I'm doing a project for a class where I'm supposed to implement the algorithms described in a research paper and run the experiments described in the paper. The paper is related to shortest-path queries, so I'm using the JUNG library; the paper and the datasets used for the experiments are found here.

Anyway part of the experiments involves comparing the memory required for the data structures used by the algorithm (a tree derived from the original graph and some info on the shortest paths) to that used by data structures in other algorithms when they're run on the same graph. The paper's author wrote the code in C++, but my prof let us choose which language to use for this project so I chose Java as I've used it a lot more and therefore code faster in it... But now I'm not sure how to figure out this memory usage thing.

I found a few questions asking similar questions but several were old (4 or 5 years) and others didn't seem to be asking quite the same question; they were calculating the size of structures that wouldn't change. So I'm hoping someone can point me to an algorithm, method, or even better a library that would give a good estimate for this. I don't think it needs to be exact, but I need some sort of estimate at least.

Maltiriel
  • 793
  • 2
  • 11
  • 28

2 Answers2

1

You want to look at various SizeOf implementations:

However, this question seems to have a better answer.

Community
  • 1
  • 1
daveb
  • 74,111
  • 6
  • 45
  • 51
  • One of the answers for that question also recommends the sizeof.sourceforge.net library, but the comments make me not so sure about it. One person said it was the same as the method described in the accepted answer, which apparently has some issues (like not being able to get the size of everything associated with a String). Can you shed some light on that at all? I'm just a bit confused on what exactly the library can do. – Maltiriel Apr 18 '12 at 15:44
  • Well, if I were to implement this for your scenario, then I think I would add a method to the data structures that did this estimation, since they would know to look into strings etc. The trouble is that java options can specify strings should be stored as byte[] not char[] so this is all quite shakey – daveb Apr 18 '12 at 16:00
  • Your data structures may be deliberately sharing strings, in which case a generic solution would double count. So it really depends on your situation. – daveb Apr 18 '12 at 16:04
  • Hmm. So I guess the general idea is that there's no easy way (like a library) to get a really good estimate? – Maltiriel Apr 18 '12 at 16:38
  • Not that I would rely on if you want the estimate to be good. You could ask a profiler to give you the deep size, but you'd need to understand how it dealt with shared objects. – daveb Apr 18 '12 at 16:41
  • Ok, thanks for the help. I guess my next step is asking the professor just how good of an estimate she wants for this part. I didn't think it'd be this complicated initially. – Maltiriel Apr 18 '12 at 18:46
0

I think that depends of implementation of Java Virtual Machine. In the document http://java.sun.com/docs/books/jni/download/jni.pdf or in http://en.wikipedia.org/wiki/Java_Native_Interface the types mapping to C++ to Java.

By example,

a java boolean type is unsigned char jboolean unsigned 8 bits

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148