Page 1 of 1

A OOP class for dynamically implementing arrays! (upgraded!)

Posted: Fri Nov 09, 2007 11:20 pm
by srod
Update : 9/12/2007.
This is proving to be more useful than I imagined it would be when I first wrote this utility! Consequently, I have seen fit to add two additional methods and to think very carefully about a potential dll problem (described below and in detail within the user guide).

The new methods are :
  • SwapElements() - no explanation required here I think! :) This is very fast even with structured arrays because all it does in these cases is swap pointers etc.
  • GetPointerToValue().
    Now this is for structured array classes only and is much faster than the GetValue() method in these cases because it does not populate a given structure from an array, but simply returns a pointer. (DO NOT use this pointer to directly alter string fields within the array itself though!)
Now this second method has been added because (speed issues aside), for structured arrays containing string fields, it is not 'safe' to use the GetValue() method across a 'dll boundary'. This is because PB dll's use a separate heap upon which to store their strings.
Please see the user guide for a detailed explanation of this.

Of course, this is really only an issue for those who decide to stuff the code for the array classes within a dll and attempt to call the resulting functions from the host application etc. Not a problem in general, just for this rather special case.

Download

============================================


Hi,

this is the second of my long standing utilities which I've now converted to OOP and this one I use more than any other utility I possess. Indeed, as I now spend the majority of my coding time creating custom Window's controls, this utility deals very nicely with just about all of the dynamic memory requirements which creating such controls demand.

In converting to OOP I have also taken the opportunity to upgrade the library somewhat.

Basically, this library (provided in source code form) allows you to dynamically create and nest dynamic arrays of any structured type - including those containing string fields. Such arrays can be nested and embedded in structures or linked lists or even other arrays etc.

The library basically wraps PB's memory functions, but takes care to ensure, in particular, that string fields are handled correctly so that there are no memory leaks etc. This is always tricky when dealing with dynamic memory allocations and strings. I tend to avoid linked lists for such things in order to ensure threadsafety without having to resort to synchronisation techniques etc.

The library is fully cross-platform and the download includes all the source code, two examples (one each for the different types of array class) and a short user guide.

Methods exposed by each of the two array classes :
  • Destroy()
  • GetUpperBound()
  • GetValue()
  • ReDim()
  • SetValue()
  • ShiftElementsLeft()
  • ShiftElementsRight()
Download

I will ask that if you are no fan of OOP or indeed cannot see any use (or have no use) for this utility then please refrain from commenting here. Start another thread, send a pm, write a letter, send a carrier pigeon, contact your local MP... etc. :)

Posted: Fri Nov 09, 2007 11:36 pm
by milan1612
YAISP ( = YetAnotherIngeniousSrodProduction)
Quite useful, keep your oop stuff coming :)

Posted: Sat Nov 10, 2007 1:17 am
by pdwyer
:shock:

Even comes with a help Doc!

You're raising the bar around here! very 8) !

Posted: Sat Nov 10, 2007 11:55 am
by srod
Thanks. I hope it's useful.
pdwyer wrote::shock:

Even comes with a help Doc!

You're raising the bar around here! very 8) !
Nice of you to say, but such tools have to be classed as being relatively simple. :)

Posted: Sat Nov 10, 2007 8:20 pm
by Heathen
I look forward to checking this out :)

Posted: Sun Dec 09, 2007 4:03 pm
by srod
Update : 9/12/2007.
This is proving to be more useful than I imagined it would be when I first wrote this utility! Consequently, I have seen fit to add two additional methods and to think very carefully about a potential dll problem (described below and in detail within the user guide).

The new methods are :
  • SwapElements() - no explanation required here I think! :) This is very fast even with structured arrays because all it does in these cases is swap pointers etc.
  • GetPointerToValue().
    Now this is for structured array classes only and is much faster than the GetValue() method in these cases because it does not populate a given structure from an array, but simply returns a pointer. (DO NOT use this pointer to directly alter string fields within the array itself though!)
Now this second method has been added because (speed issues aside), for structured arrays containing string fields, it is not 'safe' to use the GetValue() method across a 'dll boundary'. This is because PB dll's use a separate heap upon which to store their strings.
Please see the user guide for a detailed explanation of this.

Of course, this is really only an issue for those who decide to stuff the code for the array classes within a dll and attempt to call the resulting functions from the host application etc. Not a problem in general, just for this rather special case.


Please see the first post for the download.

Posted: Sun Dec 09, 2007 9:41 pm
by SFSxOI
srod,

I've never used anything you provided that did not perform better then imagined.

Thank you very much :)

Posted: Mon Dec 10, 2007 2:40 pm
by dagcrack
Very nice srod!

Posted: Mon Dec 10, 2007 2:46 pm
by srod
You're welcome SFSxOI, dagcrack.

:)