Author Topic: bug in arralloc / arralloc$()  (Read 10202 times)

qWord

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: bug in arralloc / arralloc$()
« Reply #15 on: November 06, 2013, 07:15:21 AM »
if you are going to test for 0, do it before allocating any space
As being a dynamic data structure, it should be allowed to create a empty array (at least that is my humble opinion).
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

  • Member
  • *****
  • Posts: 10548
  • Assembler is fun ;-)
    • MasmBasic
Re: bug in arralloc / arralloc$()
« Reply #16 on: November 06, 2013, 09:52:47 AM »
As being a dynamic data structure, it should be allowed to create a empty array

Semi-dynamic, maybe. Example from hlhelp.chm:
LOCAL hArray  :DWORD
......
mov hArray, arralloc$(2048)
......
mov hArray, arrealloc$(hArray,4096)


Slightly more dynamic:
include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init                        ; ## create a dynamic string array ##
  Dim My$()
  xor ecx, ecx
  .Repeat
        Let My$(ecx)=Str$("String %i", ecx)
        inc ecx
  .Until ecx>=20000
  Inkey "ok"
  Exit
end start


But in both cases, a "true" empty array makes little sense. You wouldn't create it if you didn't want to use it, right?

P.S.: Your version is better than mine. I had not thought of accessing memory from bottom to top. I wonder, however, if the direction really matters. Testbed?  ;)

Here it is:
Intel(R) Celeron(R) M CPU        420  @ 1.60GHz (SSE3)
9947    kCycles for 5 * down
10274   kCycles for 5 * up

10205   kCycles for 5 * down
10284   kCycles for 5 * up

10155   kCycles for 5 * down
10212   kCycles for 5 * up

35      bytes for down
38      bytes for up

qWord

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: bug in arralloc / arralloc$()
« Reply #17 on: November 06, 2013, 10:39:10 AM »
OK, I didn't consider the reallocation strategy, which change the pointer/handle. Regardless that, under certain conditions it can make sense to have empty containers.
MREAL macros - when you need floating point arithmetic while assembling!