I've created a vector list (array) for PB in C called VList, (except for 3 functions, here are the functions I have completed. BUT I have a question(see below):
VListPush (vlistPtr VList, void* Data)
VListPop (vlistPtr VList)
VListOverwrite (vlistPtr VList, void* Data)
VListSelect (vlistPtr VList, int Index)
VListNext (vlistPtr VList)
VListPrevious (vlistPtr VList)
VListCreate (int Size)
VListDelete (vlistPtr VList)
VListAutoSize (vlistPtr VList)
VListResize (vlistPtr VList, int NewSize)
VListGetArray (vlistPtr VList)
VListGetData (vlistPtr VList, int Index)
VListGetIndex (vlistPtr VList)
VListGetSize (vlistPtr VList)
VListGetCount (vlistPtr VList)
Now I was just wandering if I should create a function called VListSet() that will actually set the current VList to be used effectively eliminating passing the vlistPtr. I see this as being a pain for having to make a quick call, but for say doing a tight loop this would save speed, no ? is this worth it or will it be annoying for the programmer ? would you rather just set the VList you currently want to use instead of passing it continually ? (If you are curious the functions I'm missing are VListSort, VListInsert, VListRemove)
example pseudo code:
MyList = VListCreate(100)
VListSet(MyList)
VListPush(10)
VListPush(34)
VListPush(76)
VListPop()
this example is stupid but i'm just showing what it would look like without passing a VList each time ? is this better or not, I need serious feedback
Vector List
-
Codemonger
- Enthusiast

- Posts: 384
- Joined: Sat May 24, 2003 8:02 pm
- Location: Canada
- Contact:
Vector List
<br>"I deliver Justice, not Mercy"
    - Codemonger, 2004 A.D.
    - Codemonger, 2004 A.D.
I faced a similar choice and decided to use a global var (or structure-based) to indicate the current list/whatever. Frequently used functions then have fewer/no parameters and this does help speed-wise. Over time situations arise that need a bit more flexibility so then I code a "vectored" version of the function, eg myfuncV(*p.vlist). This seems a good balance. Watch out for situations where you need recursive/re-entrant code as this can complicate things greatly and your scheme as it is might be more robust (or simply less hassle for you
) in the long term.
-
Codemonger
- Enthusiast

- Posts: 384
- Joined: Sat May 24, 2003 8:02 pm
- Location: Canada
- Contact:
Thanks dmoc, I ended up going with a global var. I was really simple to change over too. The structure is always available to the user so in a recursive situation where they are constantly changing lists, the user could either use the commands, I could make simple alternate commands for those situations or a more advanced programmer could simply tap into the array themselves and use it. I also made the decision to add in a lot of error/bound checking, so people don't have wild crashes. So the removal of taking the vlist out as a function parameter should balance this out, and the syntax seems a little cleaner too, which I like. Anyway I finished the rest of the commands and I am writing the documentation for them .. I will make addition commands to add support for floats, doubles, & bytes etc ... right now the simple 32 bit integer should suffice for most situations. Anyway thanks for the insight.
<br>"I deliver Justice, not Mercy"
    - Codemonger, 2004 A.D.
    - Codemonger, 2004 A.D.