Hi Wang,
if I understand correctly, your question is how to eliminate the memory
overhead of storing as objects rather than structs; specifically, the cost
of storing a pointer for each data element, and any padding. If you're
using Native X10, the standard C++ advice about order of data members will
help reduce padding overhead (
http://www.cprogramming.com/tutorial/size_of_class_object.html ). However
this will not eliminate pointer overhead.
Can you convert your data from an array of classes to a class with array
members? (In C++ these layouts are usually referred to as Array of Structs
[AoS] versus Struct of Arrays [SoA].)
For example, instead your existing class containing a single data item:
class Data {
val i:Int;
val j:Int;
var flag: Boolean;
var value: Int;
// other fields and methods
}
val data = new Data[N]();
you could have a single class containing all data:
class AllData {
val i:Rail[Int]; // i coords for all data (size N)
val j:Rail[Int]; // j coords in same order
val flag:Rail[Boolean];
val value:Rail[Int];
// etc.
}
val allData = new AllData(N);
As X10 Rails are just like C++ arrays, no pointers are required for an
individual data item. Note that all of the fields of AllData must be
simple scalar/struct types - a Rail of object types would still require
pointers.
Of course, the fields for each data item are now widely spaced in memory
across the different arrays. How this affects cache use will depend on how
your application accesses the data.
Do you think this would work?
Cheers,
Josh
On 19 October 2014 09:40, WangChen <wang...@163.com> wrote:
> Thanks for your quick response.
>
> But I don’t think intern will suits here.
> I mean my program need to create 1 billion instances of Data class. And
> all of them are different.
>
>
> 在 2014年10月19日,下午9:22,Vijay Saraswat <vi...@saraswat.org> 写道:
>
> > Not sure I am following you.
> >
> > Which of the billion instances do u want to eliminate?
> >
> > You could write a small piece of code to intern objects yourself, but
> > since you also have a field you need to mutate you need to think
> > carefully how u are going to manage mutation and sharing.
> >
> > (Interning is fairly well understood for Java-like languages -- u can
> > start with
> >
> http://stackoverflow.com/questions/7035659/good-pattern-for-creating-an-object-that-supports-interning
> > )
> >
> > On 10/19/14, 8:48 AM, WangChen wrote:
> >> Hi,
> >>
> >> I have a class named Data and it has some basic field like this:
> >>
> >> class Data {
> >> val i:Int;
> >> val j:Int;
> >> var flag: Boolean;
> >> var value: Int;
> >> // other fields and methods
> >> }
> >>
> >> My program will create many instances of Data, lets say 1 billion,
> which will cost a lot of memory since every instance need extra spaces.
> >>
> >> And i can’t use structs here because they are immutable but i need to
> update fields of it.
> >>
> >> So what can i do here ?
> >> Is there a way to manage memory explicitly?
> >>
> >>
> >>
> >>
> >>
> ------------------------------------------------------------------------------
> >> Comprehensive Server Monitoring with Site24x7.
> >> Monitor 10 servers for $9/Month.
> >> Get alerted through email, SMS, voice calls or mobile push
> notifications.
> >> Take corrective actions from your mobile device.
> >> http://p.sf.net/sfu/Zoho
> >> _______________________________________________
> >> X10-users mailing list
> >> X10-users@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/x10-users
> >
> >
> >
> ------------------------------------------------------------------------------
> > Comprehensive Server Monitoring with Site24x7.
> > Monitor 10 servers for $9/Month.
> > Get alerted through email, SMS, voice calls or mobile push notifications.
> > Take corrective actions from your mobile device.
> > http://p.sf.net/sfu/Zoho
> > _______________________________________________
> > X10-users mailing list
> > X10-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/x10-users
>
>
>
>
> ------------------------------------------------------------------------------
> Comprehensive Server Monitoring with Site24x7.
> Monitor 10 servers for $9/Month.
> Get alerted through email, SMS, voice calls or mobile push notifications.
> Take corrective actions from your mobile device.
> http://p.sf.net/sfu/Zoho
> _______________________________________________
> X10-users mailing list
> X10-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x10-users
>
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users