20260 RAM usage

How can I get the used and available RAM while running my program in a 20260?

GHIElectronics.TinyCLR.Native.Memory.ManagedMemory.FreeBytes shows quantities between 180,000 and 205,000

System.GC.GetTotalMemory(true) shows around 280,000.

I think those quantities are too low. (I understand the 20260 has a 32 MB RAM).

I’m asking this because my program kept hanging one minute after starting. I suspected that was caused by a lazy GC so I added a Thread that calls GC periodically. I started with a 10 secs interval, but had to lower it to 500 msec to avoid the hanging.

This is the output of GC:
GC: performing heap compaction…
GC: 1msec 279120 bytes used, 228704 bytes available
Type 11 (STRING ): 22688 bytes
Type 13 (CLASS ): 41232 bytes
Type 14 (VALUETYPE ): 992 bytes
Type 15 (SZARRAY ): 44560 bytes
Type 03 (U1 ): 19600 bytes
Type 04 (CHAR ): 20144 bytes
Type 06 (U2 ): 928 bytes
Type 07 (I4 ): 48 bytes
Type 11 (STRING ): 64 bytes
Type 13 (CLASS ): 3664 bytes
Type 14 (VALUETYPE ): 112 bytes
Type 17 (FREEBLOCK ): 228704 bytes
Type 19 (ASSEMBLY ): 17040 bytes
Type 1B (REFLECTION ): 64 bytes
Type 1D (DELEGATE_HEAD ): 1392 bytes
Type 1E (DELEGATELIST_HEAD ): 288 bytes
Type 1F (OBJECT_TO_EVENT ): 800 bytes
Type 20 (BINARY_BLOB_HEAD ): 131904 bytes
Type 21 (THREAD ): 5200 bytes
Type 22 (SUBTHREAD ): 576 bytes
Type 23 (STACK_FRAME ): 8128 bytes
Type 29 (FINALIZER_HEAD ): 96 bytes
Type 33 (IO_PORT ): 144 bytes
Type 36 (APPDOMAIN_HEAD ): 80 bytes
Type 38 (APPDOMAIN_ASSEMBLY ): 3936 bytes

Is what you need here?

https://docs.ghielectronics.com/software/tinyclr/tutorials/memory.html

https://docs.ghielectronics.com/software/tinyclr/tutorials/external-memory.html

https://docs.ghielectronics.com/software/tinyclr/tutorials/unmanaged-heap.html

Thank you Gus. I’ll check those links.

Problem solved using GHIElectronics.TinyCLR.Native.Memory.ExtendHeap().

Thanks a lot Gus.

1 Like