PC Review


Reply
Thread Tools Rate Thread

ArrayList() of Class or Struct. Best memory usage

 
 
=?Utf-8?B?UmVuem8=?=
Guest
Posts: n/a
 
      3rd Dec 2004
Hi, I use C# on Compact Framework for PPC program development. Well, I need
to use many ArrayList() of data and I don't know which is the best memory
management that I will have to use. Is more convenient to use a Class() or a
Struct() to store my data? For example (with some sintax errorrs):

class TPoint
{
int x;
int y;
}
or
struct TPoint
{
int x;
int y;
}

ArrayList MyPoints=new ArrayList();
PPoint=new TPoint();
for (iLoop=1; iLoop<=1000; iLoop++)
{
TPoint PPoint=(TPoint) MyPoints[MyPoints.Add(new TPoint())];
PPoint.x=iLoop;
PPoint.y=iLoop;
}

I read that Class() are stored in the Heap, while Struct() are stored in the
Stack memory. Well, which is the best way (for memory space, memory
performance, etc...) to store my data in PPC memory where I have a little
memory to manage?
--
Thanks in advance,
Renzo Contarini
 
Reply With Quote
 
 
 
 
Daniel Moth
Guest
Posts: n/a
 
      3rd Dec 2004
Depends on the size of struct but for the example you gave structs will be
more efficient memory wise (some suggest under 12-16 bytes go for structs
and anything more use classes). However you will incur a boxing hit if you
use value types in an ArrayList so only by measuring the real scenario
yourself can you come up with an answer. If you know how many you'll have
beforehand, struct with normal arrays is the best solution in my view (until
we get generics in the next version).

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Renzo" <(E-Mail Removed)> wrote in message
news:99B327D3-F1E3-4DAA-874E-(E-Mail Removed)...
> Hi, I use C# on Compact Framework for PPC program development. Well, I
> need
> to use many ArrayList() of data and I don't know which is the best memory
> management that I will have to use. Is more convenient to use a Class() or
> a
> Struct() to store my data? For example (with some sintax errorrs):
>
> class TPoint
> {
> int x;
> int y;
> }
> or
> struct TPoint
> {
> int x;
> int y;
> }
>
> ArrayList MyPoints=new ArrayList();
> PPoint=new TPoint();
> for (iLoop=1; iLoop<=1000; iLoop++)
> {
> TPoint PPoint=(TPoint) MyPoints[MyPoints.Add(new TPoint())];
> PPoint.x=iLoop;
> PPoint.y=iLoop;
> }
>
> I read that Class() are stored in the Heap, while Struct() are stored in
> the
> Stack memory. Well, which is the best way (for memory space, memory
> performance, etc...) to store my data in PPC memory where I have a little
> memory to manage?
> --
> Thanks in advance,
> Renzo Contarini



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing an arraylist which contains a struct which contains an arraylist Christopher H Microsoft C# .NET 3 13th Apr 2007 03:39 PM
C# CSharp Reset Struct Class Memory Sheikko Microsoft Dot NET Framework 2 29th Mar 2007 06:36 PM
C# CSharp Reset Struct Class Memory Sheikko Microsoft C# .NET 2 21st Mar 2007 08:07 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting Microsoft ASP .NET 0 29th Dec 2003 07:08 AM
Hashtable and ArrayList with bad memory usage? Matthias Kwiedor Microsoft C# .NET 7 25th Nov 2003 09:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:41 PM.