You missed my point, I was not trying to tell you anything about using Capacity, I was explaining the 700KB allocation limit and used Capacity as an example.
Mike suggestion to chain blocks is a good suggestion as it will avoid the single allocation size limit. Each block might be an ArrayList of items.
Note:
[ol]I have pushed this to 20000 instances created on each load and it worked
The complete ICollection, IList & IEnumerable implementation for LargeArrayList is left as an exercise for the reader.[/ol]
using System;
using Microsoft.SPOT;
using System.Collections;
namespace MFConsoleApplication1
{
public class Program
{
public static void Main()
{
Debug.EnableGCMessages(false);
uint waterMark = Debug.GC(true);
Debug.Print("Memory:" + waterMark);
var loader1 = new Loader();
loader1.CreateSome();
Debug.GC(true);
var loader2 = new Loader();
loader2.CreateSome();
Debug.GC(true);
Debug.Print("Memory Used:" + (waterMark - Debug.GC(true)));
Debug.Print(
Resources.GetString(Resources.StringResources.String1));
}
}
public class Loader
{
public void CreateSome()
{
for (int n = 0; n < 400; ++n)
{
_data.Add(new KmaParam() { TelegramNo = n });
}
}
LargeArrayList _data = new LargeArrayList();
}
internal class KmaParam
{
public int TelegramNo;
}
public class LargeArrayList
{
private const int ItemsPerBlock = 256;
private ArrayList _items = new ArrayList();
private ArrayList _currentBlock;
private int _count;
public void Add(object item)
{
if (_currentBlock == null || _currentBlock.Count == ItemsPerBlock)
{
_currentBlock = new ArrayList();
_items.Add(_currentBlock);
}
_currentBlock.Add(item);
_count++;
}
public object this[int index]
{
get
{
if (index < 0 || index >= _count) throw new ArgumentOutOfRangeException("index");
int block = index / ItemsPerBlock;
int blockIndex = index % ItemsPerBlock;
return ((ArrayList)_items[block])[blockIndex];
}
}
}
}
@ Reinhard Ostermeier - It is a pleasure, I hope it gets you in a position to ship your product! And credit to @ Mike, I believe this is actually what he was explaining or at least something similar.
@ taylorza - I have posted my implementation here: https://www.ghielectronics.com/community/codeshare/entry/831
It’s tested by sample code and my project.
I have chosen to not implement IList because of Insert and Remove methods.
So it ‘only’ supports ICollection++.
It’s not that I fear the implementation, but imagine inserting a new item at the beginning of a 5000 item list. Even when using a ArrayList of ArrayLists you Need to move one item over all lists to keep the block size constant.
Thats’s not very performant.
I wanted to create the optimal solution for a straight forward list. Write once read often.