News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

How much stack can we use in one procedure ?

Started by RuiLoureiro, December 08, 2016, 11:05:22 PM

Previous topic - Next topic

RuiLoureiro

Hi
I need to create a lot of LOCAL buffers and variables in one procedure.
The example is this:
Quote
stk0_var1       = 0
stk0_var2       = stk0_var1 + 20000
stk0_var3       = stk0_var2 + 20000
stk0_var4       = stk0_var3 + 20000


lenstackbuffer = stk0_var4 + 20000


ProcedureA        proc
                          push   ebp
                          sub     esp, lenstackbuffer     ; <<<<<---- this create a space of 80 000 bytes
                          mov   ebp, esp                      ;                     but the program exits HERE
etc
Jochen, Hutch, Dave, qWord, MichaelW, someone can help me ?
How to work with a stack of this dimension ?
What to do ?
Hutch, i am using your QEditor. What Project -> Assemble & Link does ?
What  .exe  it calls ?  ml and link in the bin folder ?
Thanks all  :t

jj2007

StackBuffer: buffer size is limited by start address of stack; normally, you can use close to one MB

In short: there is an awful lot of stack space for you, but unless you have MasmBasic installed, you will have to search the forum for stack probing 8)

include \masm32\MasmBasic\MasmBasic.inc      ; download
.code
MyTest proc uses edi argsize, argbyte
  mov edi, StackBuffer(argsize)
  push edi
  mov ecx, argsize
  deb 4, "we'll fill the buffer now...", ecx
  mov eax, argbyte
  rep stosb
  pop edi
  deb 4, "Buffer filled: ", $edi:20      ; show the first 20 bytes
  StackBuffer()
  ret
MyTest endp
  Init
  invoke MyTest, 10000, "a"
  invoke MyTest, 100000, "b"
  invoke MyTest, 1000000, "c"
  Inkey "ok?"
EndOfCode


I attach a demo. On Win7-64, the limit seems to be around 1030000 bytes, but of course, you can change that with a linker option.

nidud

#2
deleted

hutch--

> Hutch, i am using your QEditor. What Project -> Assemble & Link does ?

You have 2 build options, normal Window UI with "Assemble & Link" or console. The difference is in the linker subsystem options.

> What  .exe  it calls ?  ml and link in the bin folder ?

For a UI exe or dll, its RC.exe, cvtres.exe ml.exe and link.exe
For console its ml.exe and link.exe.

RE: Using large stack space, there is a reason why Microsoft never bothered to fix the slow performance, its really bad code design. Large allocations are where you use dynamic allocation which you can allocate then free. GlobalAlloc(), HeapAlloc(), VirtualAlloc() and any of the other dedicated types for OLE and COM.

If you do need large stack, nidud has shown how its done as a linker option and don't be afraid to use 2 or 4 meg in the reserve/commit as you won't see the difference but will be able to use much more stack space. It matters in code like recursive sorts and similar.

RuiLoureiro

Quote from: nidud on December 08, 2016, 11:59:29 PM
Normally LINK reserves 1M and commit one page (4096 byte).

Use the /STACK:reserve[,commit] switch to set/commit more stack.


LINK /STACK:1048576,1048576 ...


It's also possible to commit more than one page by probing the stack:

   mov   ecx,esp
   .while   eax > 0x1000      ; probe pages
      sub   eax,0x1000
      test   [ecx],ecx
      sub   ecx,0x1000
   .endw
   sub   ecx,eax
   test   [ecx],ecx      ; probe page

:biggrin: :biggrin:

Thanks so much nidud, it solved the problem: i added /STACK... to buil.bat etc. and now
i am working in 1M space, it doesnt exit in that point where we sub esp, lenstackbuffer.
;) :t

RuiLoureiro

#5
Quote from: hutch-- on December 09, 2016, 03:01:08 AM
> Hutch, i am using your QEditor. What Project -> Assemble & Link does ?

You have 2 build options, normal Window UI with "Assemble & Link" or console. The difference is in the linker subsystem options.

> What  .exe  it calls ?  ml and link in the bin folder ?

For a UI exe or dll, its RC.exe, cvtres.exe ml.exe and link.exe
For console its ml.exe and link.exe.

RE: Using large stack space, there is a reason why Microsoft never bothered to fix the slow performance, its really bad code design. Large allocations are where you use dynamic allocation which you can allocate then free. GlobalAlloc(), HeapAlloc(), VirtualAlloc() and any of the other dedicated types for OLE and COM.

If you do need large stack, nidud has shown how its done as a linker option and don't be afraid to use 2 or 4 meg in the reserve/commit as you won't see the difference but will be able to use much more stack space. It matters in code like recursive sorts and similar.
Thanks Hutch, i am trying to do this project for the first time. So i want to see the results. I have more than 300 procedures (!!!) all using the same set of tables, buffers, pointers and variables defined in the main procedure. So in this way all that more than 300 procedures are called with call and they use the variables etc. defined before.
note: all buffers are aligned by 16 in the stack. About this type of code design, i may write it in another way and then i may compare. Without that second version i dont know what is better.
Thanks  :t

RuiLoureiro

Jochen,
Thanks, you are always a big friend  :t

RuiLoureiro

#7
Hi Hutch, this is the basic and main part of the design.
These buffers, tables and variables are all used by all
procedures. Is this that you call a bad code design ?
Whats your opinion ?
note: The first 6 tables are working as memmory allocated so far
(so, not stack but it may work in the stack...).
See you  :t
Thanks  all (nidud...)
Quote
rcl0_TblRational                = 0
rcl0_TblInteger                 = rcl0_TblRational  + $MEMO512TBL10
rcl0_TblReal                    = rcl0_TblInteger   + $MEMO512TBL10
rcl0_TblBracket                 = rcl0_TblReal      + $MEMO512TBL10
rcl0_TblPower                   = rcl0_TblBracket   + $MEMO512TBL10
rcl0_TblFunction                = rcl0_TblPower     + $MEMO1024TBL10

rcl0_Express                    = 0     ;rcl0_TblFunction  + $MEMO1024TBL10
rcl0_Argument                   = rcl0_Express      + $TOTALofSTACKBUFFER4096
rcl0_Derivative                 = rcl0_Argument     + $TOTALofSTACKBUFFER4096
rcl0_Solution                   = rcl0_Derivative   + $TOTALofSTACKBUFFER4096
rcl0_ExpressA                   = rcl0_Solution     + $TOTALofSTACKBUFFER4096
rcl0_ArgumentA                  = rcl0_ExpressA     + $TOTALofSTACKBUFFER1024
rcl0_DerivativeA                = rcl0_ArgumentA    + $TOTALofSTACKBUFFER1024 
rcl0_SolutionA                  = rcl0_DerivativeA  + $TOTALofSTACKBUFFER1024
rcl0_BaseA                      = rcl0_SolutionA    + $TOTALofSTACKBUFFER1024
rcl0_ExponentA                  = rcl0_BaseA        + $TOTALofSTACKBUFFER1024
rcl0_StringKA                   = rcl0_ExponentA    + $TOTALofSTACKBUFFER1024
rcl0_StringKNA                  = rcl0_StringKA     + $TOTALofSTACKBUFFER1024
rcl0_ExpressB                   = rcl0_StringKNA    + $TOTALofSTACKBUFFER1024
rcl0_ArgumentB                  = rcl0_ExpressB     + $TOTALofSTACKBUFFER1024
rcl0_DerivativeB                = rcl0_ArgumentB    + $TOTALofSTACKBUFFER1024
rcl0_SolutionB                  = rcl0_DerivativeB  + $TOTALofSTACKBUFFER1024
rcl0_BaseB                      = rcl0_SolutionB    + $TOTALofSTACKBUFFER1024
rcl0_ExponentB                  = rcl0_BaseB        + $TOTALofSTACKBUFFER1024
rcl0_StringKB                   = rcl0_ExponentB    + $TOTALofSTACKBUFFER1024
rcl0_StringKNB                  = rcl0_StringKB     + $TOTALofSTACKBUFFER1024
rcl0_ExpressC                   = rcl0_StringKNB    + $TOTALofSTACKBUFFER1024
rcl0_ArgumentC                  = rcl0_ExpressC     + $TOTALofSTACKBUFFER1024
rcl0_DerivativeC                = rcl0_ArgumentC    + $TOTALofSTACKBUFFER1024
rcl0_SolutionC                  = rcl0_DerivativeC  + $TOTALofSTACKBUFFER1024
rcl0_BaseC                      = rcl0_SolutionC    + $TOTALofSTACKBUFFER1024
rcl0_ExponentC                  = rcl0_BaseC        + $TOTALofSTACKBUFFER1024
rcl0_StringKC                   = rcl0_ExponentC    + $TOTALofSTACKBUFFER1024
rcl0_StringKNC                  = rcl0_StringKC     + $TOTALofSTACKBUFFER1024
rcl0_ExpressD                   = rcl0_StringKNC    + $TOTALofSTACKBUFFER1024
rcl0_ArgumentD                  = rcl0_ExpressD     + $TOTALofSTACKBUFFER1024
rcl0_DerivativeD                = rcl0_ArgumentD    + $TOTALofSTACKBUFFER1024
rcl0_SolutionD                  = rcl0_DerivativeD  + $TOTALofSTACKBUFFER1024
rcl0_BaseD                      = rcl0_SolutionD    + $TOTALofSTACKBUFFER1024
rcl0_ExponentD                  = rcl0_BaseD        + $TOTALofSTACKBUFFER1024
rcl0_StringKD                   = rcl0_ExponentD    + $TOTALofSTACKBUFFER1024
rcl0_StringKND                  = rcl0_StringKD     + $TOTALofSTACKBUFFER1024
rcl0_ExpressE                   = rcl0_StringKND    + $TOTALofSTACKBUFFER1024
rcl0_ArgumentE                  = rcl0_ExpressE     + $TOTALofSTACKBUFFER1024
rcl0_DerivativeE                = rcl0_ArgumentE    + $TOTALofSTACKBUFFER1024
rcl0_SolutionE                  = rcl0_DerivativeE  + $TOTALofSTACKBUFFER1024
rcl0_BaseE                      = rcl0_SolutionE    + $TOTALofSTACKBUFFER1024
rcl0_ExponentE                  = rcl0_BaseE        + $TOTALofSTACKBUFFER1024
rcl0_StringKE                   = rcl0_ExponentE    + $TOTALofSTACKBUFFER1024
rcl0_StringKNE                  = rcl0_StringKE     + $TOTALofSTACKBUFFER1024
rcl0_ExpressF                   = rcl0_StringKNE    + $TOTALofSTACKBUFFER1024
rcl0_ArgumentF                  = rcl0_ExpressF     + $TOTALofSTACKBUFFER1024
rcl0_DerivativeF                = rcl0_ArgumentF    + $TOTALofSTACKBUFFER1024
rcl0_SolutionF                  = rcl0_DerivativeF  + $TOTALofSTACKBUFFER1024
rcl0_BaseF                      = rcl0_SolutionF    + $TOTALofSTACKBUFFER1024
rcl0_ExponentF                  = rcl0_BaseF        + $TOTALofSTACKBUFFER1024
rcl0_StringKF                   = rcl0_ExponentF    + $TOTALofSTACKBUFFER1024
rcl0_StringKNF                  = rcl0_StringKF     + $TOTALofSTACKBUFFER1024
rcl0_TblOperation               = rcl0_StringKNF    + $TOTALofSTACKBUFFER1024
rcl0_NumberKA                   = rcl0_TblOperation + 32            ; 6 factors * 4=24 + 8 Max,Len = 32   
rcl0_NumberNA                   = rcl0_NumberKA     + 16
rcl0_NumberKNA                  = rcl0_NumberNA     + 16
rcl0_NumberKB                   = rcl0_NumberKNA    + 16 
rcl0_NumberNB                   = rcl0_NumberKB     + 16
rcl0_NumberKNB                  = rcl0_NumberNB     + 16
rcl0_NumberKC                   = rcl0_NumberKNB    + 16 
rcl0_NumberNC                   = rcl0_NumberKC     + 16
rcl0_NumberKNC                  = rcl0_NumberNC     + 16
rcl0_NumberKD                   = rcl0_NumberKNC    + 16 
rcl0_NumberND                   = rcl0_NumberKD     + 16
rcl0_NumberKND                  = rcl0_NumberND     + 16
rcl0_NumberKE                   = rcl0_NumberKND    + 16 
rcl0_NumberNE                   = rcl0_NumberKE     + 16
rcl0_NumberKNE                  = rcl0_NumberNE     + 16
rcl0_NumberKF                   = rcl0_NumberKNE    + 16 
rcl0_NumberNF                   = rcl0_NumberKF     + 16
rcl0_NumberKNF                  = rcl0_NumberNF     + 16
;                   Pointers
rcl0_pTblRational               = rcl0_NumberKNF    + 16
rcl0_pTblInteger                = rcl0_pTblRational + 4
rcl0_pTblReal                   = rcl0_pTblInteger  + 4
rcl0_pTblBracket                = rcl0_pTblReal     + 4
rcl0_pTblPower                  = rcl0_pTblBracket  + 4
rcl0_pTblFunction               = rcl0_pTblPower    + 4
rcl0_pExpress                   = rcl0_pTblFunction + 4
rcl0_pArgument                  = rcl0_pExpress     + 4
rcl0_pDerivative                = rcl0_pArgument    + 4
rcl0_pSolution                  = rcl0_pDerivative  + 4
rcl0_pExpressA                  = rcl0_pSolution    + 4
rcl0_pArgumentA                 = rcl0_pExpressA    + 4
rcl0_pDerivativeA               = rcl0_pArgumentA   + 4
rcl0_pSolutionA                 = rcl0_pDerivativeA + 4
rcl0_pBaseA                     = rcl0_pSolutionA   + 4
rcl0_pExponentA                 = rcl0_pBaseA       + 4
rcl0_pStringKA                  = rcl0_pExponentA   + 4
rcl0_pStringKNA                 = rcl0_pStringKA    + 4
rcl0_pExpressB                  = rcl0_pStringKNA   + 4
rcl0_pArgumentB                 = rcl0_pExpressB    + 4
rcl0_pDerivativeB               = rcl0_pArgumentB   + 4
rcl0_pSolutionB                 = rcl0_pDerivativeB + 4
rcl0_pBaseB                     = rcl0_pSolutionB   + 4
rcl0_pExponentB                 = rcl0_pBaseB       + 4
rcl0_pStringKB                  = rcl0_pExponentB   + 4
rcl0_pStringKNB                 = rcl0_pStringKB    + 4
rcl0_pExpressC                  = rcl0_pStringKNB   + 4
rcl0_pArgumentC                 = rcl0_pExpressC    + 4
rcl0_pDerivativeC               = rcl0_pArgumentC   + 4
rcl0_pSolutionC                 = rcl0_pDerivativeC + 4
rcl0_pBaseC                     = rcl0_pSolutionC   + 4
rcl0_pExponentC                 = rcl0_pBaseC       + 4
rcl0_pStringKC                  = rcl0_pExponentC   + 4
rcl0_pStringKNC                 = rcl0_pStringKC    + 4
rcl0_pExpressD                  = rcl0_pStringKNC   + 4
rcl0_pArgumentD                 = rcl0_pExpressD    + 4
rcl0_pDerivativeD               = rcl0_pArgumentD   + 4
rcl0_pSolutionD                 = rcl0_pDerivativeD + 4
rcl0_pBaseD                     = rcl0_pSolutionD   + 4
rcl0_pExponentD                 = rcl0_pBaseD       + 4
rcl0_pStringKD                  = rcl0_pExponentD   + 4
rcl0_pStringKND                 = rcl0_pStringKD    + 4
rcl0_pExpressE                  = rcl0_pStringKND   + 4
rcl0_pArgumentE                 = rcl0_pExpressE    + 4
rcl0_pDerivativeE               = rcl0_pArgumentE   + 4
rcl0_pSolutionE                 = rcl0_pDerivativeE + 4
rcl0_pBaseE                     = rcl0_pSolutionE   + 4
rcl0_pExponentE                 = rcl0_pBaseE       + 4
rcl0_pStringKE                  = rcl0_pExponentE   + 4
rcl0_pStringKNE                 = rcl0_pStringKE    + 4
rcl0_pExpressF                  = rcl0_pStringKNE   + 4
rcl0_pArgumentF                 = rcl0_pExpressF    + 4
rcl0_pDerivativeF               = rcl0_pArgumentF   + 4
rcl0_pSolutionF                 = rcl0_pDerivativeF + 4
rcl0_pBaseF                     = rcl0_pSolutionF   + 4
rcl0_pExponentF                 = rcl0_pBaseF       + 4
rcl0_pStringKF                  = rcl0_pExponentF   + 4
rcl0_pStringKNF                 = rcl0_pStringKF    + 4
rcl0_MType                      = rcl0_pStringKNF   + 4
rcl0_SType                      = rcl0_MType        + 4
rcl0_kFunc                      = rcl0_SType        + 4
rcl0_MTypeA                     = rcl0_kFunc        + 4
rcl0_STypeA                     = rcl0_MTypeA       + 4
rcl0_kFuncA                     = rcl0_STypeA       + 4
rcl0_BasMTypeA                  = rcl0_kFuncA       + 4
rcl0_BasSTypeA                  = rcl0_BasMTypeA    + 4
rcl0_BaskFuncA                  = rcl0_BasSTypeA    + 4
rcl0_ArgMTypeA                  = rcl0_BaskFuncA    + 4
rcl0_ArgSTypeA                  = rcl0_ArgMTypeA    + 4
rcl0_ArgkFuncA                  = rcl0_ArgSTypeA    + 4
rcl0_MTypeB                     = rcl0_ArgkFuncA    + 4
rcl0_STypeB                     = rcl0_MTypeB       + 4
rcl0_kFuncB                     = rcl0_STypeB       + 4
rcl0_BasMTypeB                  = rcl0_kFuncB       + 4
rcl0_BasSTypeB                  = rcl0_BasMTypeB    + 4
rcl0_BaskFuncB                  = rcl0_BasSTypeB    + 4
rcl0_ArgMTypeB                  = rcl0_BaskFuncB    + 4
rcl0_ArgSTypeB                  = rcl0_ArgMTypeB    + 4
rcl0_ArgkFuncB                  = rcl0_ArgSTypeB    + 4
rcl0_MTypeC                     = rcl0_ArgkFuncB    + 4
rcl0_STypeC                     = rcl0_MTypeC       + 4
rcl0_kFuncC                     = rcl0_STypeC       + 4
rcl0_BasMTypeC                  = rcl0_kFuncC       + 4
rcl0_BasSTypeC                  = rcl0_BasMTypeC    + 4
rcl0_BaskFuncC                  = rcl0_BasSTypeC    + 4
rcl0_ArgMTypeC                  = rcl0_BaskFuncC    + 4
rcl0_ArgSTypeC                  = rcl0_ArgMTypeC    + 4
rcl0_ArgkFuncC                  = rcl0_ArgSTypeC    + 4
rcl0_MTypeD                     = rcl0_ArgkFuncC    + 4
rcl0_STypeD                     = rcl0_MTypeD       + 4
rcl0_kFuncD                     = rcl0_STypeD       + 4
rcl0_BasMTypeD                  = rcl0_kFuncD       + 4
rcl0_BasSTypeD                  = rcl0_BasMTypeD    + 4
rcl0_BaskFuncD                  = rcl0_BasSTypeD    + 4
rcl0_ArgMTypeD                  = rcl0_BaskFuncD    + 4
rcl0_ArgSTypeD                  = rcl0_ArgMTypeD    + 4
rcl0_ArgkFuncD                  = rcl0_ArgSTypeD    + 4
rcl0_MTypeE                     = rcl0_ArgkFuncD    + 4
rcl0_STypeE                     = rcl0_MTypeE       + 4
rcl0_kFuncE                     = rcl0_STypeE       + 4
rcl0_BasMTypeE                  = rcl0_kFuncE       + 4
rcl0_BasSTypeE                  = rcl0_BasMTypeE    + 4
rcl0_BaskFuncE                  = rcl0_BasSTypeE    + 4
rcl0_ArgMTypeE                  = rcl0_BaskFuncE    + 4
rcl0_ArgSTypeE                  = rcl0_ArgMTypeE    + 4
rcl0_ArgkFuncE                  = rcl0_ArgSTypeE    + 4
rcl0_MTypeF                     = rcl0_ArgkFuncE    + 4
rcl0_STypeF                     = rcl0_MTypeF       + 4
rcl0_kFuncF                     = rcl0_STypeF       + 4
rcl0_BasMTypeF                  = rcl0_kFuncF       + 4
rcl0_BasSTypeF                  = rcl0_BasMTypeF    + 4
rcl0_BaskFuncF                  = rcl0_BasSTypeF    + 4
rcl0_ArgMTypeF                  = rcl0_BaskFuncF    + 4
rcl0_ArgSTypeF                  = rcl0_ArgMTypeF    + 4
rcl0_ArgkFuncF                  = rcl0_ArgSTypeF    + 4
rcl0_pTblOperation              = rcl0_ArgkFuncF    + 4             ; 84996
rcl0_pNumberKA                  = rcl0_pTblOperation+ 4 
rcl0_pNumberNA                  = rcl0_pNumberKA    + 4
rcl0_pNumberKNA                 = rcl0_pNumberNA    + 4
rcl0_pNumberKB                  = rcl0_pNumberKNA   + 4 
rcl0_pNumberNB                  = rcl0_pNumberKB    + 4
rcl0_pNumberKNB                 = rcl0_pNumberNB    + 4
rcl0_pNumberKC                  = rcl0_pNumberKNB   + 4
rcl0_pNumberNC                  = rcl0_pNumberKC    + 4
rcl0_pNumberKNC                 = rcl0_pNumberNC    + 4
rcl0_pNumberKD                  = rcl0_pNumberKNC   + 4 
rcl0_pNumberND                  = rcl0_pNumberKD    + 4
rcl0_pNumberKND                 = rcl0_pNumberND    + 4
rcl0_pNumberKE                  = rcl0_pNumberKND   + 4 
rcl0_pNumberNE                  = rcl0_pNumberKE    + 4
rcl0_pNumberKNE                 = rcl0_pNumberNE    + 4
rcl0_pNumberKF                  = rcl0_pNumberKNE   + 4 
rcl0_pNumberNF                  = rcl0_pNumberKF    + 4
rcl0_pNumberKNF                 = rcl0_pNumberNF    + 4
rcl0_pTblTerms                  = rcl0_pNumberKNF   + 4           ; 85 072
rcl0_kSubTypeA                  = rcl0_pTblTerms    + 4
rcl0_kSubTypeB                  = rcl0_kSubTypeA    + 4
rcl0_NumFactors                 = rcl0_kSubTypeB    + 4
rcl0_BufferNumber               = rcl0_NumFactors   + 4
rcl0_Operation                  = rcl0_BufferNumber + 4
LenOfStackBuffer                = rcl0_Operation    + 4
rcl0_pRclStr                    = LenOfStackBuffer  + 8
;-----------------------------------------------------------------
rcl_TblRational                 equ dword ptr [ebp+rcl0_TblRational]
rcl_TblInteger                  equ dword ptr [ebp+rcl0_TblInteger]
rcl_TblReal                     equ dword ptr [ebp+rcl0_TblReal]
rcl_TblBracket                  equ dword ptr [ebp+rcl0_TblBracket]
rcl_TblPower                    equ dword ptr [ebp+rcl0_TblPower]
rcl_TblFunction                 equ dword ptr [ebp+rcl0_TblFunction]
rcl_Express                     equ dword ptr [ebp+rcl0_Express]
rcl_Argument                    equ dword ptr [ebp+rcl0_Argument]
rcl_Derivative                  equ dword ptr [ebp+rcl0_Derivative]
rcl_Solution                    equ dword ptr [ebp+rcl0_Solution]

rcl_pExponentD                  equ dword ptr [ebp+rcl0_pExponentD]
rcl_pStringKD                   equ dword ptr [ebp+rcl0_pStringKD]
rcl_pStringKND                  equ dword ptr [ebp+rcl0_pStringKND]
rcl_pExpressE                   equ dword ptr [ebp+rcl0_pExpressE]
rcl_pArgumentE                  equ dword ptr [ebp+rcl0_pArgumentE]
rcl_pDerivativeE                equ dword ptr [ebp+rcl0_pDerivativeE]
rcl_pSolutionE                  equ dword ptr [ebp+rcl0_pSolutionE]
rcl_pBaseE                      equ dword ptr [ebp+rcl0_pBaseE]
rcl_pExponentE                  equ dword ptr [ebp+rcl0_pExponentE]
rcl_pStringKE                   equ dword ptr [ebp+rcl0_pStringKE]
rcl_pStringKNE                  equ dword ptr [ebp+rcl0_pStringKNE]
rcl_pExpressF                   equ dword ptr [ebp+rcl0_pExpressF]
rcl_pArgumentF                  equ dword ptr [ebp+rcl0_pArgumentF]
rcl_pDerivativeF                equ dword ptr [ebp+rcl0_pDerivativeF]
rcl_pSolutionF                  equ dword ptr [ebp+rcl0_pSolutionF]
rcl_pBaseF                      equ dword ptr [ebp+rcl0_pBaseF]


hutch--

> Is this that you call a bad code design ? Whats your opinion ?

I can't tell you a lot from what you have posted but it looks more like a very large structure than a simple memory allocation but its not what you are using it for that is the problem, I made the comment that rather than using BBS memory which increases the size of you exe memory footprint, you are better off to use dynamically allocated memory like Heap or Global alloc. In Win32 you can routinely allocate 1 gig of memory if your computer has enough memory and it happens very quickly so there is nothing to prevent you from doing an allocation for each table and have an array at the front of each table as an array of pointers.

This would be efficient, fast and very flexible.

RuiLoureiro

#9
Thanks for your opinion, Hutch. Yes it is a very large structure of buffers, pointers, tables, variables.
It is working just now in The Calculator to do derivatives following a new way of to do (it's my new way !).The Calculator uses a lot of memmory allocated using global alloc and i save the addresses in pointers. Each time we define a matrix, for example, it allocs a 20*21 *32 (16 for real part and 16 for imaginary part). If  we define 10 matrices we need to multiply the last number by 10 more or less (i  save a header behind the address).
When  The Calculator starts, it allocs a lot of memmory to many things, not to do derivatives. Well, i need to write 299 procs yet to complete the procedures to give the derivative of any expression (correctly)  :P .
Thanks
See you\ :t
note: 300=10 * 10 cases * 2 operations + 10*10 power cases :biggrin: :biggrin:
EDIT: dont be afraid, the derivative of a lot of them are null ;)

Adamanteus

Quote from: RuiLoureiro on December 08, 2016, 11:05:22 PM
                          sub     esp, lenstackbuffer     ; <<<<<---- this create a space of 80 000 bytes
This line is real problem - as it could not be such much stayed stack in particular moment of working program !
In this topic such task is implemented by __chkstk or __alloca_probe from C runtime, as this is requirement of operating system !
So, possible use macro or do it manualy ...

jj2007

Quote from: Adamanteus on December 11, 2016, 02:53:43 AM
Quote from: RuiLoureiro on December 08, 2016, 11:05:22 PM
                          sub     esp, lenstackbuffer     ; <<<<<---- this create a space of 80 000 bytes
This line is real problem - as it could not be such much stayed stack in particular moment of working program !

OMG, yes, eightythousand bytes :dazzled:

include \masm32\MasmBasic\MasmBasic.inc      ; download
.data
smin      SDWORD 7fffffffh

.code
MinStack:
  .if esp<smin
      mov smin, esp
  .endif
  ret

  Init
  GfCallback MinStack
  GetFiles "\Masm32\*.as?"      ; heavily recursive...
  push eax
  GetFolders "\Masm32"
  pop ecx
  mov edx, esp
  sub edx, smin
  deb 4, "files, folders found, stack: current, minimum, difference:", ecx, eax, esp, smin, edx
EndOfCode


Output:
files, folders found, stack: current, minimum, difference:
ecx             8646
eax             2628
esp             1638284
smin            1627952
edx             10332

RuiLoureiro

#12
Hi all
Hutch,
         Here it is the basic structure that i will use to
         give the derivative of an expression. I have
         A,B,C,D,E,F plus 6 and each one is double: A and AA, B and BB,...
         Today i tested and all (24) are correct (total structure length = 114 028 bytes).
         As you can see i am using a table of pointers and all elements
         are called with any_variables (see below).
         Have you any comment ?
         Thank you
See you  :t
         
Quote
;-----------------------------------------------------
;            space to load factor  A
;-----------------------------------------------------
rcl0_ExpressA                   equ rcl0_pResNumberL1F   + 4
rcl0_ArgumentA                  equ rcl0_ExpressA        + $TOTALofSTACKBUFFER512
rcl0_DerivativeA                equ rcl0_ArgumentA       + $TOTALofSTACKBUFFER512
rcl0_SolutionA                  equ rcl0_DerivativeA     + $TOTALofSTACKBUFFER512

rcl0_ExpressAA                  equ rcl0_SolutionA       + $TOTALofSTACKBUFFER512
rcl0_ArgumentAA                 equ rcl0_ExpressAA       + $TOTALofSTACKBUFFER512
rcl0_DerivativeAA               equ rcl0_ArgumentAA      + $TOTALofSTACKBUFFER512
rcl0_SolutionAA                 equ rcl0_DerivativeAA    + $TOTALofSTACKBUFFER512

rcl0_BaseA                      equ rcl0_SolutionAA      + $TOTALofSTACKBUFFER512
rcl0_ExponentA                  equ rcl0_BaseA           + $TOTALofSTACKBUFFER512
rcl0_BaseAA                     equ rcl0_ExponentA       + $TOTALofSTACKBUFFER512
rcl0_ExponentAA                 equ rcl0_BaseAA          + $TOTALofSTACKBUFFER512

rcl0_StringKA                   equ rcl0_ExponentAA      + $TOTALofSTACKBUFFER512
rcl0_StringK1A                  equ rcl0_StringKA        + $TOTALofSTACKBUFFER128

rcl0_StringLA                   equ rcl0_StringK1A       + $TOTALofSTACKBUFFER128
rcl0_StringL1A                  equ rcl0_StringLA        + $TOTALofSTACKBUFFER128

rcl0_MTypeA                     equ rcl0_StringL1A       + $TOTALofSTACKBUFFER128
rcl0_STypeA                     equ rcl0_MTypeA          + 4
rcl0_kFuncA                     equ rcl0_STypeA          + 4

rcl0_BasMTypeA                  equ rcl0_kFuncA          + 4
rcl0_BasSTypeA                  equ rcl0_BasMTypeA       + 4
rcl0_BaskFuncA                  equ rcl0_BasSTypeA       + 4

rcl0_DrvMTypeA                  equ rcl0_BaskFuncA       + 4
rcl0_DrvSTypeA                  equ rcl0_DrvMTypeA       + 4
rcl0_DrvkFuncA                  equ rcl0_DrvSTypeA       + 4

rcl0_ArgMTypeA                  equ rcl0_DrvkFuncA       + 4
rcl0_ArgSTypeA                  equ rcl0_ArgMTypeA       + 4
rcl0_ArgkFuncA                  equ rcl0_ArgSTypeA       + 4

rcl0_ExpMTypeA                  equ rcl0_ArgkFuncA       + 4
rcl0_ExpSTypeA                  equ rcl0_ExpMTypeA       + 4
rcl0_ExpkFuncA                  equ rcl0_ExpSTypeA       + 4

rcl0_FncMTypeA                  equ rcl0_ExpkFuncA       + 4
rcl0_FncSTypeA                  equ rcl0_FncMTypeA       + 4
rcl0_FnckFuncA                  equ rcl0_FncSTypeA       + 4

rcl0_PowMTypeA                  equ rcl0_FnckFuncA       + 4
rcl0_PowSTypeA                  equ rcl0_PowMTypeA       + 4
rcl0_PowkFuncA                  equ rcl0_PowSTypeA       + 4

rcl0_BraMTypeA                  equ rcl0_PowkFuncA       + 4
rcl0_BraSTypeA                  equ rcl0_BraMTypeA       + 4
rcl0_BrakFuncA                  equ rcl0_BraSTypeA       + 4

rcl0_CstMTypeA                  equ rcl0_BrakFuncA       + 4
rcl0_CstSTypeA                  equ rcl0_CstMTypeA       + 4
rcl0_CstkFuncA                  equ rcl0_CstSTypeA       + 4
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rcl0_MTypeAA                    equ rcl0_CstkFuncA       + 4
rcl0_STypeAA                    equ rcl0_MTypeAA         + 4
rcl0_kFuncAA                    equ rcl0_STypeAA         + 4

rcl0_BasMTypeAA                 equ rcl0_kFuncAA         + 4
rcl0_BasSTypeAA                 equ rcl0_BasMTypeAA      + 4
rcl0_BaskFuncAA                 equ rcl0_BasSTypeAA      + 4

rcl0_DrvMTypeAA                 equ rcl0_BaskFuncAA      + 4
rcl0_DrvSTypeAA                 equ rcl0_DrvMTypeAA      + 4
rcl0_DrvkFuncAA                 equ rcl0_DrvSTypeAA      + 4

rcl0_ArgMTypeAA                 equ rcl0_DrvkFuncAA      + 4
rcl0_ArgSTypeAA                 equ rcl0_ArgMTypeAA      + 4
rcl0_ArgkFuncAA                 equ rcl0_ArgSTypeAA      + 4

rcl0_ExpMTypeAA                 equ rcl0_ArgkFuncAA      + 4
rcl0_ExpSTypeAA                 equ rcl0_ExpMTypeAA      + 4
rcl0_ExpkFuncAA                 equ rcl0_ExpSTypeAA      + 4

rcl0_FncMTypeAA                 equ rcl0_ExpkFuncAA      + 4
rcl0_FncSTypeAA                 equ rcl0_FncMTypeAA      + 4
rcl0_FnckFuncAA                 equ rcl0_FncSTypeAA      + 4

rcl0_PowMTypeAA                 equ rcl0_FnckFuncAA      + 4
rcl0_PowSTypeAA                 equ rcl0_PowMTypeAA      + 4
rcl0_PowkFuncAA                 equ rcl0_PowSTypeAA      + 4

rcl0_BraMTypeAA                 equ rcl0_PowkFuncAA      + 4
rcl0_BraSTypeAA                 equ rcl0_BraMTypeAA      + 4
rcl0_BrakFuncAA                 equ rcl0_BraSTypeAA      + 4

rcl0_CstMTypeAA                 equ rcl0_BrakFuncAA      + 4
rcl0_CstSTypeAA                 equ rcl0_CstMTypeAA      + 4
rcl0_CstkFuncAA                 equ rcl0_CstSTypeAA      + 4
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rcl0_NumberKA                   equ rcl0_CstkFuncAA      + 4
rcl0_NumberNA                   equ rcl0_NumberKA        + 16
rcl0_NumberK1A                  equ rcl0_NumberNA        + 16

rcl0_NumberLA                   equ rcl0_NumberK1A       + 16
rcl0_NumberMA                   equ rcl0_NumberLA        + 16
rcl0_NumberL1A                  equ rcl0_NumberMA        + 16
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;                                                  Pointers
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rcl0_pExpressA                  equ rcl0_NumberL1A       + 16
rcl0_pArgumentA                 equ rcl0_pExpressA       + 4
rcl0_pDerivativeA               equ rcl0_pArgumentA      + 4
rcl0_pSolutionA                 equ rcl0_pDerivativeA    + 4

rcl0_pBaseA                     equ rcl0_pSolutionA      + 4
rcl0_pExponentA                 equ rcl0_pBaseA          + 4

rcl0_pMTypeA                    equ rcl0_pExponentA      + 4
rcl0_pBasMTypeA                 equ rcl0_pMTypeA         + 4
rcl0_pDrvMTypeA                 equ rcl0_pBasMTypeA      + 4
rcl0_pArgMTypeA                 equ rcl0_pDrvMTypeA      + 4
rcl0_pExpMTypeA                 equ rcl0_pArgMTypeA      + 4
rcl0_pFncMTypeA                 equ rcl0_pExpMTypeA      + 4
rcl0_pPowMTypeA                 equ rcl0_pFncMTypeA      + 4
rcl0_pBraMTypeA                 equ rcl0_pPowMTypeA      + 4
rcl0_pCstMTypeA                 equ rcl0_pBraMTypeA      + 4

rcl0_pStringKA                  equ rcl0_pCstMTypeA      + 4
rcl0_pStringK1A                 equ rcl0_pStringKA       + 4

rcl0_pNumberKA                  equ rcl0_pStringK1A      + 4
rcl0_pNumberNA                  equ rcl0_pNumberKA       + 4
rcl0_pNumberK1A                 equ rcl0_pNumberNA       + 4
;--------------------------------
rcl0_pExpressAA                 equ rcl0_pNumberK1A      + 4
rcl0_pArgumentAA                equ rcl0_pExpressAA      + 4
rcl0_pDerivativeAA              equ rcl0_pArgumentAA     + 4
rcl0_pSolutionAA                equ rcl0_pDerivativeAA   + 4

rcl0_pBaseAA                    equ rcl0_pSolutionAA     + 4
rcl0_pExponentAA                equ rcl0_pBaseAA         + 4

rcl0_pMTypeAA                   equ rcl0_pExponentAA     + 4
rcl0_pBasMTypeAA                equ rcl0_pMTypeAA        + 4
rcl0_pDrvMTypeAA                equ rcl0_pBasMTypeAA     + 4
rcl0_pArgMTypeAA                equ rcl0_pDrvMTypeAA     + 4
rcl0_pExpMTypeAA                equ rcl0_pArgMTypeAA     + 4
rcl0_pFncMTypeAA                equ rcl0_pExpMTypeAA     + 4
rcl0_pPowMTypeAA                equ rcl0_pFncMTypeAA     + 4
rcl0_pBraMTypeAA                equ rcl0_pPowMTypeAA     + 4
rcl0_pCstMTypeAA                equ rcl0_pBraMTypeAA     + 4

rcl0_pStringLA                  equ rcl0_pCstMTypeAA     + 4
rcl0_pStringL1A                 equ rcl0_pStringLA       + 4

rcl0_pNumberLA                  equ rcl0_pStringL1A      + 4
rcl0_pNumberMA                  equ rcl0_pNumberLA       + 4
rcl0_pNumberL1A                 equ rcl0_pNumberMA       + 4
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

; rcl_pExpressA     equ dword ptr [ebp+rcl0_pExpressA]
; rclpExpressA      equ 0
;
; lea               ebx, rcl_pExpressA
; mov               rcl_TableA, ebx
;
any_pExpressX       equ dword ptr [ebx+rclpExpressA]        ; ebx +0
any_pArgumentX      equ dword ptr [ebx+rclpArgumentA]       ;     +4
any_pDerivativeX    equ dword ptr [ebx+rclpDerivativeA]     ;     +8 ... etc
any_pSolutionX      equ dword ptr [ebx+rclpSolutionA]
any_pBaseX          equ dword ptr [ebx+rclpBaseA]
any_pExponentX      equ dword ptr [ebx+rclpExponentA]

any_pMTypeX         equ dword ptr [ebx+rclpMTypeA]
any_pBasMTypeX      equ dword ptr [ebx+rclpBasMTypeA]
any_pDrvMTypeX      equ dword ptr [ebx+rclpDrvMTypeA]
any_pArgMTypeX      equ dword ptr [ebx+rclpArgMTypeA]
any_pExpMTypeX      equ dword ptr [ebx+rclpExpMTypeA]
any_pFncMTypeX      equ dword ptr [ebx+rclpFncMTypeA]
any_pPowMTypeX      equ dword ptr [ebx+rclpPowMTypeA]
any_pBraMTypeX      equ dword ptr [ebx+rclpBraMTypeA]
any_pCstMTypeX      equ dword ptr [ebx+rclpCstMTypeA]

any_pStringKX       equ dword ptr [ebx+rclpStringKA]
any_pStringK1X      equ dword ptr [ebx+rclpStringK1A]

any_pNumberKX       equ dword ptr [ebx+rclpNumberKA]
any_pNumberNX       equ dword ptr [ebx+rclpNumberNA]
any_pNumberK1X      equ dword ptr [ebx+rclpNumberK1A]
;+++++++++++++++++++++++++++++++++++++++++++++++++++++
any_pExpressXX      equ dword ptr [ebx+rclpExpressAA]
any_pArgumentXX     equ dword ptr [ebx+rclpArgumentAA]
any_pDerivativeXX   equ dword ptr [ebx+rclpDerivativeAA]
any_pSolutionXX     equ dword ptr [ebx+rclpSolutionAA]
any_pBaseXX         equ dword ptr [ebx+rclpBaseAA]
any_pExponentXX     equ dword ptr [ebx+rclpExponentAA]

any_pMTypeXX        equ dword ptr [ebx+rclpMTypeAA]
any_pBasMTypeXX     equ dword ptr [ebx+rclpBasMTypeAA]
any_pDrvMTypeXX     equ dword ptr [ebx+rclpDrvMTypeAA]
any_pArgMTypeXX     equ dword ptr [ebx+rclpArgMTypeAA]
any_pExpMTypeXX     equ dword ptr [ebx+rclpExpMTypeAA]
any_pFncMTypeXX     equ dword ptr [ebx+rclpFncMTypeAA]
any_pPowMTypeXX     equ dword ptr [ebx+rclpPowMTypeAA]
any_pBraMTypeXX     equ dword ptr [ebx+rclpBraMTypeAA]
any_pCstMTypeXX     equ dword ptr [ebx+rclpCstMTypeAA]

any_pStringKXX      equ dword ptr [ebx+rclpStringKAA]
any_pStringK1XX     equ dword ptr [ebx+rclpStringK1AA]

any_pNumberKXX      equ dword ptr [ebx+rclpNumberKAA]
any_pNumberNXX      equ dword ptr [ebx+rclpNumberNAA]
any_pNumberK1XX     equ dword ptr [ebx+rclpNumberK1AA]