News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

bug in arralloc / arralloc$()

Started by qWord, November 04, 2013, 09:37:17 AM

Previous topic - Next topic

qWord

Quote from: dedndave on November 06, 2013, 06:47:54 AMif 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

Quote from: qWord on November 06, 2013, 07:15:21 AMAs 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

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!