It's been a long time since I saw disassembled PowerBASIC code, but if I recall, all local variables in subroutine are allocated on the stack. Strings of course come from the string heap, but the local pointer is still stored on the stack. I belive also that variables of type STRING * n (static strings) are allocated on the stack as well, as are UDTs. In C, the alloca command provides for easy allocation of memory on the stack. Even in the old DOS days. As long as your stack size is sufficient, there is no problem.
------------------
Announcement
Collapse
No announcement yet.
Is this 'safe' for PB/DOS programs?
Collapse
X
-
OK, it does work. I just altered one of my production
OBJ file functions to use it. Instead of using a 128-byte
BYTE string declared in the DATA section, I allocated 128 bytes
of temporary storage on the function's stack. The function is one
that runs a second program as specified by the calling code, and
returns the second program's exit code to the calling code. When I
ran a couple of my main EXE's that use the function, I did not get
any Windows errors, and the function worked as it normally does.
So, the only remaining question is whether it is actually safe?
Yes, I am aware that the stack segment in DOS is not as nearly
big as it is in 32-bit programs, and that the CPU might very well
shut down if I "overload" the stack. But, that should never be a
problem as all of my PB/DOS EXE's use a 16384 STACK. I never have
come close to filling it up.
So, Lance, Paul, Bob, Tom, is the method "OK" to use?
------------------
Leave a comment:
-
Is this 'safe' for PB/DOS programs?
I apologize for asking this, as I prefer to find out myself
from empirical test coding. However, since this could
conceivably trash my PB/DOS EXE's, and therefore
my OS, I'd prefer to find out by asking first.
This question, as far as my production usage, would pretty much only
apply to OBJ file subs/functions linked into my main PB/DOS EXE's.
In a thread in the Programming Forum, Mr. Paul Dixon used a technique I had
never seen before to allocate a local storage buffer.
To wit:
Code:FUNCTION blah-blah (arg&&, arg2&&) AS STRING 'some code ! pushad ! [b]sub esp, 12[/b] ! [b]mov edi, esp[/b] 'main ASM code ! [b]add esp, 12[/b] ! popad 'rest of code END FUNCTION
used by PB/DOS EXE's? Or is the stack methods of DOS programs too
different from 32-bit programs for it to be used? (naturally, the
DOS procedures would use 16-bit addressing, not 32-bit).
Any assistance gratefully received.
------------------
Tags: None
Leave a comment: