Announcement

Collapse
No announcement yet.

Is this 'safe' for PB/DOS programs?

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

  • 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
            ! sub esp, 12
            ! mov edi, esp
            'main ASM code
            ! add esp, 12
            ! popad
            'rest of code
        END FUNCTION
    Could the same method be used to allocate temp storage in subs/functions
    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.


    ------------------

  • #2
    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?



    ------------------

    Comment


    • #3
      Not a problem

      Bob Zale
      PowerBASIC Inc.


      ------------------

      Comment


      • #4
        Thanks, Bob.


        ------------------

        Comment


        • #5
          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.


          ------------------

          Comment

          Working...
          X