View Full Version : varable index buffer setup unsing a varable
longpole001
- 25th November 2020, 04:38
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
HenrikOlsson
- 25th November 2020, 06:30
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.
longpole001
- 25th November 2020, 07:39
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
longpole001
- 25th November 2020, 08:14
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
mpgmike
- 25th November 2020, 21:10
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.
richard
- 26th November 2020, 03:18
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
longpole001
- 27th November 2020, 01:30
thats interesting thought and approach, maybe worth a look to just see if it works
thanks richard ,
richard
- 27th November 2020, 01:38
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)
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.