Announcement

Collapse
No announcement yet.

Need some help with em_AllocV

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

  • Need some help with em_AllocV

    Hi,

    I have a make a memory declaration. and a clear declaration in func main(),

    board := mem_AllocV(100); //Reserve some memory
    mem_Set(board,0x00,sizeof(board)*2); // fill board with "0"

    I wont to set position 50 to 99, and later I won't to read position 50

    How should I do that?

    I found also that the value of sizeof(board) was zero.
    What is going wrong?

    I have used the example "BIGARRAY" as an example


    Cheers

    Jan

  • #2
    board can be simply treated as an array, so board[50] will be the 16bit integer in element 50.

    sizeof is for the number of array elements of array variables, so a normal variable will always return 0, this includes normal variables that have a pointer mem_Alloced into it

    Currently the -1 element contains the size in bytes of the allocation, so maybe you can use that, if you really need it
    Mark

    Comment


    • #3
      Thanks,

      When I compile my code I get a notice : variable 'board' is being indexed.
      Do I need to do some actions?

      Cheers,

      Jan

      Comment


      • #4
        Not really, if you want to get rid of the notice, just add an * to the start of the declaration, eg
        var *board ;
        Mark

        Comment


        • #5
          Hi,

          I wrote this simple code, and fill the block with a fixed value of 123.
          When I run the next numbers are displayed

          23205
          256
          770
          1284

          What is wrong on my code?

          Cheers,

          Jan


          var *board;

          func main()

          board := mem_AllocV(100); //allocate the memmory
          mem_Set(board,123,sizeof(board)*2); //clear memmory block
          print(board[0],"\n");
          print(board[1],"\n");
          print(board[2],"\n");
          print(board[3],"\n");

          repeat // maybe replace
          forever // this as well

          endfunc

          Comment


          • #6
            First problem, you can't use sizeof, read what I said earlier.

            Second problem, you asked about clearing memory, setting it to 0 will work.

            When you set a string of bytes(8 bits) to 123 (0x7b), integers(16 bits) at those locations will be 0x7b7b, or decimal 31611
            Mark

            Comment


            • #7
              Thanks again, but I don't understand it.
              Why is this simple code not work?

              Cheers,

              Jan


              var *board;

              func main()
              print("Memmory test\n");
              board := mem_AllocV(100); //allocate the memmory
              board[50]:=1234;
              mem_Set(board,0,100); //clear memmory block
              print(board[50],"\n"); <<<<<<<<= is not set to the value I won't

              repeat // maybe replace
              forever // this as well

              endfunc

              Comment


              • #8
                Arrays are 0 based, so board[50] is outside the bounds of the array. Board[49] is the highest element
                Mark

                Comment

                Working...
                X