Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Just a Few Questions
#11
@bplus I doubt using a dynamic array to emulate a true stack will aid with those 2 things, it should be relatively straightforward to implement a faux stack. (a queue and/or a deque on the other hand...). Just need a simple variable to hold the ToS (Top of Stack) and use Redim _Preserve somewhat liberally.

TR
Reply
#12
(09-10-2023, 01:45 PM)TarotRedhand Wrote: @bplus I doubt using a dynamic array to emulate a true stack will aid with those 2 things, it should be relatively straightforward to implement a faux stack. (a queue and/or a deque on the other hand...). Just need a simple variable to hold the ToS (Top of Stack) and use Redim _Preserve somewhat liberally.

TR
Just curious, where would a stack be handy in QB64 programming?

I created a stack like structure in my Super Megabug game way back in 2010 to store locations of maze endpoints as random mazes are created. But I used a stack structure simply because I was new to QB64 and was familiar with their use when I programmed in Assembler. I could have just as easily used an array.

Perhaps a fixed (static) sized _MEM structure could be used and a stack pointer indicating the current memory location much the same as was done in Assembler. Depending on the pointer use you could create a LIFO or FIFO stack. I think using _REDIM _PRESERVE would be rather slow for something like a stack that is constantly updating.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#13
(09-10-2023, 02:47 PM)TerryRitchie Wrote:
(09-10-2023, 01:45 PM)TarotRedhand Wrote: @bplus I doubt using a dynamic array to emulate a true stack will aid with those 2 things, it should be relatively straightforward to implement a faux stack. (a queue and/or a deque on the other hand...). Just need a simple variable to hold the ToS (Top of Stack) and use Redim _Preserve somewhat liberally.

TR
Just curious, where would a stack be handy in QB64 programming?

I created a stack like structure in my Super Megabug game way back in 2010 to store locations of maze endpoints as random mazes are created. But I used a stack structure simply because I was new to QB64 and was familiar with their use when I programmed in Assembler. I could have just as easily used an array.

Perhaps a fixed (static) sized _MEM structure could be used and a stack pointer indicating the current memory location much the same as was done in Assembler. Depending on the pointer use you could create a LIFO or FIFO stack. I think using _REDIM _PRESERVE would be rather slow for something like a stack that is constantly updating.

I use LIFO stacks for return lines from GoSubs in my interpreter and use LIFO stack when converting a recursive routine to a manual routine not using built in recursion of QB64.

@grymmjack I got paged twice by Terry's post above?
b = b + ...
Reply
#14
Quote:Just curious, where would a stack be handy in QB64 programming?
A stack is used where there are an arbitrary number of temporary values that need to be retained for an arbitrary length of time. Or, in English Wink , When you have one or more values that you think will be needed at a later point in the program but you don't know the exact number of values that will need retaining. The other thing to note is that the values are retrieved from a stack in reverse order to how they were added - i.e. the last value added is the first retrieved (Last In, First Out aka LIFO).

In QB64PE, emulated stacks are less useful due to not being able to add an array to to user-defined type. This in effect limits you to a single global (emulated) stack.

TR
Reply
#15
(09-10-2023, 02:47 PM)TerryRitchie Wrote: Perhaps a fixed (static) sized _MEM structure could be used and a stack pointer indicating the current memory location much the same as was done in Assembler. Depending on the pointer use you could create a LIFO or FIFO stack. I think using _REDIM _PRESERVE would be rather slow for something like a stack that is constantly updating.

I agree with this, instead of begging for something that could complicate the QB64 source code that deals with UDT's. Besides, one could write something that is compatible with the "official" QB64 as well.

Yes, I don't like using `REDIM _PRESERVE` (only "preserve" keyword carries the underscore in this BASIC dialect, Terry) for only one element of any type or size.
Reply
#16
(09-11-2023, 09:11 AM)TarotRedhand Wrote: In QB64PE, emulated stacks are less useful due to not being able to add an array to to user-defined type. This in effect limits you to a single global (emulated) stack.
There's a newish feature to be able to use a variable-length `String` in UDTs. It's slightly buggy at the moment, but it does work, and it's possible to use `String` as a stack (which will then automatically grow as you add too it).
Reply




Users browsing this thread: 4 Guest(s)