Java and memory management

I am new to java world with C ++ background. I would like to port some C ++ code to Java. The code uses Sparse vectors:

struct Feature{
int index;
double value;
};

typedef std::vector<Feature> featvec_t;

As I understand it, if someone creates an object, there will be some overhead for using memory. Thus, the naive implementation of Feature will be significant if there are 10-100 million functions in the featvec_t suite.

How to efficiently represent this memory structure in Java?

+3
source share
4 answers

If memory is really your bottleneck, try storing data in two separate arrays: int[] indexand double[] value.

() . , (, , ..), Feature. java.util.Collection, (List, Set ..) , java.util.

+6

, java.util.List<Feature>, int double Feature .

, TIntArrayList TDoubleArrayList GNU trove.

+5

? , ...

, Java /.

, TreeMap, .

+1

Java ( ) :

  • SizeOf ()
  • SizeOf ()
  • sizeof ( *) < -

, . 4 + 8 = 12 , 33%... () .

0

Source: https://habr.com/ru/post/1728160/


All Articles