Out of memory but free memory is around 4MB

@ Makla, @ andre.marschalek, @ Reinhard Ostermeier, @ Justin

.NETMF does not allow a single allocation to exceed around 768KB (It is actually bit less than that). If you want to allocate larger buffers then you need to allocate those buffers off the custom heap using LargeBuffer.

But, keep in mind that the Custom Heap is limited, I will need to double check, but on the Hydra I believe the limit is a little less than 4MB.

1 Like

@ taylorza - Yes i know, and yes in 4.2 it has been fixed at 4mb :slight_smile:

@ taylorza - Out of curiosity do you have a G120 or HDR?

I assumed that you might not be aware of the limit because of the above quote.

No, I do not. Have been considering getting one, but might rather just wait for the Cobra II.

I think that whatever.mybuffer is only a reference to the same buffer as another.testbuffer after you have called whatever.test.
At least I hope it is like that. If not every array would be copied when you pass it to a method (as it is done for int, …).
I think arrays are like classes, not like basic types, which are in fact like structs.

@ taylorza - drats - was going to get you to test something for me… o well… i will have to pester Gus :smiley:

Sorry I can’t help. I would be happy to oblige otherwise.

@ Reinhard Ostermeier -

Yeah I understand what your talking about. It s a kind of Flip Flop sytem that enable to prepare a buffer while you’re managing the first one and then swap between them to avoid dead time. Effectively I also used such mechanism for Vidéo playback.

but as I said, you have to ensure that the Total amount of memory needed by the several threads is sufficient, and this is not the case in many hardware implementations of embedded (and cost effective) devices, and it is important to make compromizes between memory uses and need for big data mangement.

As far as I’m concerned, such embedded devices proposed here are not intending to compete with some like BeagleBone, but more to propose effective HW for IoT tasks. And that however the Chipworkx and G120 have several MB of avaiable RAM/FLASH.

@ LouisCpro - I never meant to code like this for ‘real’ embedded devices. There you usually go for DMA, hardware decoders and that stuff to accomplish such a thing.
I do not see a EMX or a G120 as an pure embedded system. They have evolved to mini computers already. (Thats just what I think).
This is also the reason why we (at my company) have choosen the G120 as the core for all solutions where modern PC’s are too ‘big’ (in size and computing power) and too unpredictable (modern computer have real slow PCI busses sometimes, don’t even think about the spontanious resource usage of AntiVirus software).

@ Reinhard Ostermeier -

You’re right, sometimes I also think that if we continue like this, Antivirus will become has stronger as the virus themselves :slight_smile:

We also decided to implment the G120 and Chipworkx as our solution and glad to see that at least we are not alone !

Hope you’ll achieve your goal. My only last waiting point is about the integration of SSL for HTTP server and the use of DPWS that seems to have a problem on 4.2 (not tested yet…).

@ LouisCpro - We are just at the beginning.
We send out a Cobra I to control a car seat mounting structure the next days. Unforuenatelly our G120 based board is not even in prototyping state, so we use the Cobra we had for early evaluation issues.
The next projects for the G120 are a controller for our measurement electronics and car seat interface board (currently connected by a TTL/IO card directly to PC).
We also have it in mind as a gateway between industrial machines and IT systems. But the we would need two network interfaces, which is not supported directly.
On the side I work on a CIFS/SMB client, wich also might be used in the gateway project.
So we see a great future in the G120 board.

I did i quick test (i am using spider):


            Debug.Print("Program Started");

            byte[] data;
            int length = 0;
            int multiplier = 10000;
            Debug.EnableGCMessages(false);
            int count = 0;
            int[] values = new int[10];
            try
            {
                while (true)
                {
                    length += multiplier;
                    try
                    {
                        data = new byte[length];
                        Debug.Print("Length:" + length.ToString() + " " + Debug.GC(true).ToString());
                    }
                    catch (OutOfMemoryException)
                    {
                        if (multiplier == 1)
                        {
                            Debug.Print("Finished. Max length is " + length.ToString());
                            values[count] = length;
                            count++;
                            length = 0;
                            multiplier = 10000;

                            if (count == 10)
                                break;
                            else
                                continue;
                        }
                        Debug.Print("Exceeded: " + length.ToString());
                        length -= multiplier;
                        multiplier = multiplier / 10;
                        Debug.Print("Multiplier changed to " + multiplier.ToString());
                    }
                }
                foreach (int value in values)
                    Debug.Print("Max length is " + value.ToString());
            }
            catch (Exception e)
            {
                Debug.Print("Length: " + length.ToString() + ", error: " + e.Message);
            }


It outputs:

If i write only

byte[] data = new byte[786366];

i get error:

Yup as @ taylorza said max object size without custom heap is ~768kb
With custom heap it’s around 4mb

And Moreover, blocks are allocated by pieces of 64KB, so do not think precision will be 1 octet when you define your buffer. In fact it will allocate a complete block even if you need several octets in it !!