How to handle a memory allocation

Designing hardware and software for systems that use the VS1010 MP3 Audio DSP Microcontroller.
Post Reply
Arek
Senior User
Posts: 98
Joined: Thu 2016-09-01 10:58

How to handle a memory allocation

Post by Arek » Fri 2019-05-31 15:03

Hi Panu,

my program grows and grows...

To avoid reporting “End of memory”, I decided to split the main program into two parts.
It means.
After the start my program checked the input data and depending on their value:
- goes on (starting values are still checked). From this stage, there is no more transition to the "B" program possible.
- the "B" program starts, which, among others supports USB. From this stage also is no return to the "A" possible.
Unless by restart, of course.

My problem.
The start of the "B" program ends with a message: “E'Out Of Mem 2!'”

Question.
How can I remove, in this case, unnecessary parts of the program "A" from memory?
Any kind of "destructors" or "free mems".

Many thanks for any suggestion

am

Hannu
Senior User
Posts: 66
Joined: Mon 2016-05-30 11:54

Re: How to handle a memory allocation

Post by Hannu » Mon 2019-06-03 10:33

Hi,

The error is that you don't have enough Y memory.

But the solutions... The best way to release memory is to exit from program. Worse would be tweak memory reservation manually, but it is the road to madness.

If your only execution path is first a.dlx then b.dlx put them to config.txt. This works if a.dlx doesn't need to pass data to b.dlx. The execution of b.dlx is just exiting from a.dlx and all the resources are freed. And restart to a.dlx is reboot.

If you need to pass data between the applications, the safest method would be have your own application.dlx which would be small as possible and run other programs. There are
ioresult shellcmd(char *cmd, char *params); and int RunLib(const char *filename, char *parameters); functions to execute programs.

Then you can run a.dlx, b.dlx and so on. When the program exits, the return value is 16 bits. ioresult or int which are about same thing. You can use return values to make decisions what to run next.

You can pass data through parameter pointer. If simple text as an input isn't enough, nothing isn't preventing misusing the parameter pointer. And being pointer, the program can write back if the single return value isn't enough. Please be careful if working like this.

My magic cookie is to put DEL and NULL as parameter and giving that from prompt would be little bit difficult.

Code: Select all

/* common header in super program and sample */
struct someStuff {
  u_int16 magic0;
  u_int16 magic1;
  u_int16 stuff0;
  u_int16 stuffMore;
};
/* In super program*/
....
struct someStuff myStuff = {
  127, 0, 42, 15
};

....
  shellcmd("sample", (char *)&myStuff);
  printf("More stuff %u\n", myStuff.stuffMore);
....
/* sample.dlx main function */
ioresult main(char *param) {
  struct someStuff *stuff;
  if (param[0] == 127 && param[1] == 0) {
     stuff = (struct someStuff *)param;
     printf("Meaning of life is %u\n",stuff->stuff0);
     stuff->stuffMore++;
     ....
  } else {
    printf("Not my magic cookie\n");
    return S_ERROR;
  }
}

Arek
Senior User
Posts: 98
Joined: Thu 2016-09-01 10:58

Re: How to handle a memory allocation

Post by Arek » Tue 2019-06-04 9:56

Hi Hannu,

thank you very much for your tips!
I chose the method with a small starter which decides to continue with the program "A" or "B".
Looks very nice but... the limitation of vs1010 not allow you to run it.
Get again "E'Out Of Mem 2!'" (Start via Termite without errors).
I divide this subprogram again in two parts and problem will be solved.

Many thanks!
am

Post Reply