Available RAM Memory

The SC20260 has 1M RAM. I created the simple blink program, and used:

var freeRam = GHIElectronics.TinyCLR.Native.Memory.ManagedMemory.FreeBytes;
var usedRam = GHIElectronics.TinyCLR.Native.Memory.ManagedMemory.UsedBytes;

at the beginning. The result:

It doesn’t add up. Where did all the RAM go ???

Yes that is not available to application. There is a dedicated heap for application.

How big is the dedicated heap ?

Free+ used

I am currently using the uc5550. Running this:


I get this:

This shows a full 32 Mb of ram. The SC20260 has the same SDRAM chip as the UC5550. Why isn’t the full 32Mb of RAM available ?

I am concerned because my current design uses a lot of RAM.

Can I access the SDRAM in an unmanaged heap?

That 32MB memory Unmanaged Heap and you are checking the heap size. This is how you check the unmanaged heap size http://new-docs.ghielectronics.com/software/tinyclr/tutorials/unmanaged-heap.html

Unmanaged is only available of graphics normally but fear not, you can enable for your application if you want. Read this please http://new-docs.ghielectronics.com/software/tinyclr/tutorials/external-memory.html

TinyCLR 1.0 included the 32Mb external RAM in the heap. Why did that change on 2.0 ?

TinyCLR 1.0 is not secure! 2.0 gives you the option to use external heap for data or keep it just for graphics, the default.

Oh, OK. I am having trouble fitting what I need into < 500 Kb. I have successfully inplemented a large string array into external RAM as well as storing Bitmaps read from files.

During startup I often do GC.Collect() in order to keep processing. I do get this:

Failed allocation for 752 blocks, 12032 bytes

Which is not an exception. Everything appears to function properly though. Is that message an indication of garbage collection ?

something like new Brush()…, new SolidBrush(), new Rectangle()…, don’t call them every loop.

Or end of the loop, try call


Those lines don’t effect drawing performance, but help a lot to avoid the messages you got.

Those failed allocations simply say it couldn’t allocate contiguous memory for your new object, which usually leads to GC to re-spread objects in memory and free up contiguous blocks. As you note they’re a soft-fail message not an exception that stops your app, they are just a notice of what is happening


I am able to read bitmap files from SD card and store them directly to external memory. It is stored as a byte array. In order to do a DrawImage I have to convert the byte array to an Image. I am reading the byte array to a MemoryStream and then to Bitmap. This however uses managed memory and there is often not enough available, resulting in out of memory exception. Is there a way to display an Image ( bitmap) directly from external memory ?

Bitmaps are always in unmanaged heap (external memory). You should not use BMP files, use JPEG or GIF, read those in a byte array (secure memroy) and then from there create the “Bitmap”, which is allocated in external memory. Once you have it, discard the byte array as it is no longer needed.

I am assuming you did not call EnableFullHeap of course.

So simply assigning the Jpeg or gif to a bitmap will put it in unmanaged ? So to draw it I just refer to the assigned bitmap variable.

What does Enablefullheap do ? Where is it ?

You are over thinking this :slight_smile: “Bitmap” uses unmanaged heap if there is one. No exceptions!

Sorry, it is enable external heap. If you make this call then everything go into external memory and will have unlimited memory! But you are less secure. You have options!

Is there any noticeable loss of performance using this external memory ?
I’m asking because it was the case with NETMF on the STM32F429 Disco.

GHIElectronics.TinyCLR.Native.Memory.EnableExternalHeap() is indefined ??
 is undefined

This is an M7 with cache. You will not notice much of of performance difference with external memory.

1 Like