varable index buffer setup unsing a varable


+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    812

    Default varable index buffer setup unsing a varable

    been a while since been playing on pbp so be nice

    like to have variable to set the index range for test3 , but not sure how to make it work , works for constants for sure

    test1 var byte
    test2 var byte

    test3 var byte[test1 * test2]

    cheers

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,329

    Default Re: varable index buffer setup unsing a varable

    Allocation of memory is done at compile time - not during runtime. Hence the content of a variable can not dictate the size of an array since the content of a variable, by definition, can change during runtime while the size of the array is allocated at compile time.

    You really can't resize arrays at runtime like what you're suggesting/expecting.

    Can you elaborate on what problem is is you're trying to solve?

    /Henrik.

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    812

    Default Re: varable index buffer setup unsing a varable

    hi hendric

    its an exiting program that uses named constants to set the buffer size , the same named constants are used in multi locations to set other variables and math

    problem is now need to set those named constants to be variables , which is ok for all , except setup the size of array bytes


    i dont want to change all the code just for this issue , but not sure how i can get arround it nicely

    cheers sheldon

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    812

    Default Re: varable index buffer setup unsing a varable

    i can fix the problem by assign the max value used to buffer array , but it just a waist of buffers when they are not needed when the value should be lower than the max number , just goes against the grain

  5. #5
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    354

    Default Re: varable index buffer setup unsing a varable

    Unfortunately, the Linker will reserve memory you claim at compile time. I can only suggest reserve test3 var byte[maximum expected size]. Unless you're scarce on SRAM, it shouldn't matter.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    1,841

    Default Re: varable index buffer setup unsing a varable

    this may be a possibility i have not got around t trying it, it may need asm support
    i kind of forget the vagaries of pbp labels
    asm var RAM_END is set to last byte allocated by pbp
    Ram past RAM_END and the physical end of memory is unused and could be allocated via the ext modifier
    eg
    buff var byte ext ;allocate a label

    @buff=RAM_END (might need +1 , can't remember); set the label address of unused memory start

    as long as you don't try to index buff past the physical end of memory i don't see any issue
    you should calculate the amount you have first
    This is more entertaining than Free to Air TV

  7. #7
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    812

    Default Re: varable index buffer setup unsing a varable

    thats interesting thought and approach, maybe worth a look to just see if it works

    thanks richard ,

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    1,841

    Default Re: varable index buffer setup unsing a varable

    i got it a bit mixed up RAM_END is the last physical byte for chip
    so you need to read lst file to see where allocated mem finishes.
    pic18's only of course
    so ...
    buff max size = RAM_END -(addr of highest allocated byte)

    @buff=(addr of highest allocated byte+1)
    Last edited by richard; - 27th November 2020 at 02:00.
    This is more entertaining than Free to Air TV

Similar Threads

  1. HSERIN string starting index ?
    By gunayburak in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 4th July 2016, 22:54
  2. strange word varable array results
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 26th October 2015, 00:01
  3. Index a bit through a portion of a port
    By ecoli-557 in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 12th March 2012, 22:22
  4. How to index Port variable
    By jpadin1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th February 2010, 10:36
  5. Access pin using index
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 16th October 2008, 02:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts