Main Site Documentation

Failure in allocate large size of memory


#1

I write a program which need to allocate byte array in size of 8 mb. (I get file from the user and use it for burn on flash memory, I get the data from SD card or from network)
when I tried to implement it- I got “Out Of Memory” exception.

when I tried to understand the issues I thought about some question, that I would like some one answer me:

  1. what size of memory is optional allocate for one variable?

  2. what size of memory is optional allocate in one declaration statement?

  3. what is the whole size of memory of the heap?-
    what is the max size of the sum of the whole variables in the gadeteer?

  4. what the action should be if I use more than the memory I can use- which exception, etc.?

and general question to all- what do you think is the right way to solve my problem?


#2

There a limit of ~70k for one variable to put in managed heap. If you need larger arrays, use Microsoft.SPOT.Hardware.LargeBuffer class, they go to unmanaged heap. Possibilities will be limited, though.

  1. and 2. ~70k, I believe (do not remember exactly).
  2. Depends on the device, EMX has 8MB of managed heap I think, and there’s some reserved for RLP in unmanaged part of the RAM.
  3. OutOfMemory?

#3

@ Simon from Vilnius - 700K not 70K :slight_smile:


#4

No shit :open_mouth: Looks like I have just found so spare resources to use…


#5

thanks
ן ,want to understand more-

when you say there is ~8MB managed heap, it include the code segment, isn’t it?
I want to know the size of the variables segment and if it depends in the size of another things.

I use FEZ spider, EMX… I saw it has “User available flash- 2.5 mb” -how can I use it?


#6

Since NETMF manages RAM for you, the whole managed heap is shared and there’s no such thing as “code segment” or any other segment. RAM usage depends on the libraries you use and deploy. Minimal NETMF footprint is a few hundred kBytes; to see exactly how much free memory you have, run the following program:

public static void Main() {
    Debug.GC(true);
    while(true){
        Thread.Sleep(1000);
    }
}

Run it and check debug output window. You’ll find detailed information of RAM usage there.

To use for what? If for your program, then you do not need to do anything special. If you want to save something at runtime, then look for the ExtendedWeakReference class (can’t remember now where exactly it is). However, I find it difficult to use for anything more than occasional writes. If you need lots of data to save/load, look for other options (like external FRAM and FLASH chips).