Announcement

Collapse
No announcement yet.

How to share memory between 4FN/4XE functions ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to share memory between 4FN/4XE functions ?

    Hi all,

    I'm using a uOLED32024-P1 with 4DLGL WorkShop 2.4 / pmmC 1.08.

    My application needs to be composed of multiple functions in 4FN/4XE files.
    (I can't write the entire application in only one file, or it will be impossible to maintain it in the future...)

    Each function in a 4FN/4XE file must share variables with others. (these variables are global to the application)

    I use the 4DGL 'file_Exec()' function to make my functions call each others.

    This 4DLG function allows to provide arguments to the called function.

    I want to provide only one argument to my sub functions: a pointer to an array which contains all shared variables.
    (Actually, the number of shared variables will often change during the application development, giving a pointer to an array is the best way to limit code modifications for each shared variable added/removed since it is easy to change the array size, and the constants referencing each variable index in the array).

    I'm trying to do sample programs to validate this architecture, but I don't succeed...

    Here is an exemple of what I'm trying to get:

    Caller program:

    Code:
    #platform "uOLED-32024-P1"var args[2];var mem[10];func main()gfx_Cls();args[0] := 1;args[1] := mem;mem[5] := 0x1234;print("args[0] = ", [HEX4] args[0],"\nargs[1] = ", [HEX4] args[1],"\nmem[5] = ", [HEX4] mem[5],"\n&mem[0] = ", [HEX4] &mem[0],"\n&mem[5] = ", [HEX4] &mem[5]);pause(4000);file_Exec("CALLED.4FN", args);endfunc
    It outputs:
    args[0] = 0001
    args[1] = 0003
    mem[5] = 1234
    &mem[0] = 0003
    &mem[5] = 0008

    Then the called program:

    Code:
    #platform "uOLED-32024-P1"func main(var a)gfx_Cls();print("a = ", [HEX4] a,"\n");print("a[5] = ", [HEX4] a[5],"\n");repeatforever;endfunc
    It outputs:
    a = 0003
    a[5] = 0000


    The value given through the argument list (0003) is correct. But why a[5] is not equal to 0x1234 ?? Does the memory is reseted ?

    Does someone knows what is happening here ? I MUST share variables between my 4FN/4XE programs...


    For information, I also tried another version of the caller program, whit only this changes :

    var mem[10]; is modified by var mem;

    and I use memory allocation for mem :

    mem := mem_Alloc(10);

    Doing this way, it does not work anymore...

  • #2


    Hi thanks, the main calling program should be able to pass a pointer to a control array to a sub program as a 'global' solution to shared memory. We will run some tests and make some example code for you and post asap. A new release of PmmC will be available in 3-4 weeks so if there is a problem it will be addressed accordingly.
    Regards,
    Dave

    Comment


    • #3
      Hi

      Thanks for your reply. Example programs would be very help full !!

      I read your post about memory spaces and I think this sample caller program should work:

      [pre]#platform "uOLED-32024-P1"


      var args[2];
      var mem;

      func main()

      gfx_Cls();

      mem := mem_Alloc(10);

      args[0] := 1;
      args[1] := mem;

      mem[5] := 0x1234;

      print("args[0] = ", [HEX4] args[0],"\nargs[1] = ", [HEX4] args[1],"\nmem[5] = ", [HEX4] mem[5],"\n&mem[0] = ", [HEX4] &mem[0],"\n&mem[5] = ", [HEX4] &mem[5]);
      pause(4000);

      file_Exec("CALLED.4FN", args);

      endfunc[/pre]
      But it does not work...

      Anyway, I'll continue to try it, and I'm also waiting for samples programs.

      Thanks

      Comment

      Working...
      X