News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

hutch's dynamic array

Started by joemc, March 06, 2010, 07:29:00 AM

Previous topic - Next topic

joemc

http://www.masm32.com/board/index.php?topic=9165.msg66361#msg66361

I have not finished reading over all of the posts for dynamic arrays, I hear hutch talk about improving it... but how would this compare to a C++ STL vector?

In the end what i am trying to achieve is a tab control that can grow or shrink from 1 to a fairly large number.  I may just go with a linked list since i can probably figure out a decent performing one myself. 

The other idea i have is an "array" of pointers that is obviously larger than needed and just dynamically create the data.

I will read more but just wanted to hear a few opinions.

jj2007

What exactly do you mean with a "dynamic" array? Something like this?

Quoteinclude \masm32\MasmBasic\MasmBasic.inc   ; the library is here

.code
start:   Dim My$(4)
   For_ n=0 To 4
      Let My$(n)="Tab "+Str$(5-n)
   Next
   Insert My$(0)
   Let My$(0)="Tab 0, inserted"
   Insert My$(3)
   Let My$(3)="Tab 3, inserted"
   Delete My$(1)
   Print "The array:"
   For_ n=0 To 5
      Print Str$("\nArray element #%i\t", n), My$(n)
   Next
   QSort My$()
   Print CrLf$, CrLf$, "The array, sorted:"
   For_ n=0 To 5
      Print Str$("\nArray element #%i\t", n), My$(n)
   Next
   inkey Chr$(13, 10, 10, "Press any key")
   Exit
end start

The array:
Array element #0        Tab 0, inserted
Array element #1        Tab 4
Array element #2        Tab 3, inserted
Array element #3        Tab 3
Array element #4        Tab 2
Array element #5        Tab 1

The array, sorted:
Array element #0        Tab 0, inserted
Array element #1        Tab 1
Array element #2        Tab 2
Array element #3        Tab 3
Array element #4        Tab 3, inserted
Array element #5        Tab 4

japheth

Quote from: joemc on March 06, 2010, 07:29:00 AM
In the end what i am trying to achieve is a tab control that can grow or shrink from 1 to a fairly large number.  I may just go with a linked list since i can probably figure out a decent performing one myself. 

The other idea i have is an "array" of pointers that is obviously larger than needed and just dynamically create the data.

I will read more but just wanted to hear a few opinions.

What you want to do is absolutely sufficiently covered by a simple linked list - or nothing at all, because the array is probably adequately managed by the control itself, see the lParam member of TCITEM.

hutch--

Joe,

The technique behind the dynamic arrays in the last masm32 version are a basic logic of an array of handles that each point to a seperately allocated block of memory and its virtue is it can be adjusted from very small to very large dynamically. The price is a single static allocation chopped up in whatever way you like is a lot faster to start and to change but it is not adjustable like a dynamic array.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php