Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Anonymous arrays?

Author
Message
Dewi Morgan
18
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 28th Jan 2008 21:51
One of the reasons I left DB in 2001 was the arrays - I got really narked off when trying to write quaternion versions of all the (then) euler-only stuff. You couldn't pass arrays, nor return them.

Apparently the language has advanced somewhat since those days. So what's the solution now, if I want to write a function to sort arbitrary data?

The only way I can see to pass arrays around is "save array" to a virtual disk, and call the function with the filename and arraylength to read in

Can I pass an array pointer to a function? Or return one?
Or wrap arrays in user-defined data structures, and pass those around?
Or even convert arrays to memblocks and back, and pass them around?
Or are there alternatives to arrays that do the same job?
I'm not picky how it's done, even using third party DLLs, so long as it's doable.

Yet another game programmer
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 28th Jan 2008 22:01
Without any DLLs it's not really possible. IIRC IanM made .. something Not sure though. I gave up on DBPro for the same reasons. If you want really good flexibility, go with C++ and the DarkGDK.

Your signature has been erased by a mod
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 28th Jan 2008 22:07
You can pass memory pointers though.

Maybe you can try to store arrays in a memory?


It only works with integers and bytes though...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Jan 2008 22:14
You can take a look at my array plug-in (use the link to my old site) - you can do some fairly tricky stuff with it, and if you're really careful, your program won't crash



The one limitation that I can remember is that resizing an array that has been passed by pointer is a no-no. If you resize, you get a new pointer, and if you don't take care and relink all of the arrays that refer to the old one to the new one (including the original array), you'll get memory corruption or crashes.

Some of the commands in the readme.txt aren't quite correct in the spelling, but you can get the correct ones from the ini file.

Dewi Morgan
18
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 29th Jan 2008 11:49 Edited at: 29th Jan 2008 11:58
Hrm. Should I go the easy way or the hard way?

The easy way would be to use that dll and take the risk, which has the downside that every call to a function that uses them needs to get a pointer to the array first, and then pass it. Not a huge disadvantage.

The hard way would be to roll my own array functions, including functions to import/export DBP arrays (and maybe matrixes, bitmaps etc), along with stack, queue, hashtable, sorting, keysorting, flipping, swapping, splicing, and all the other stuff that I've grown to know and love from languages like Perl and PHP. And then DLLify it all.

I think the easy way may end up being more painful in the long run, and the hard way may teach me more. So if nobody else has already done this, and anyone thinks these features might be useful, then I'll give it a bash, though I daresay I'll fail miserably

It feels a pity that people are leaving DBP because it is not powerful enough, when it feels like it can be *made* powerful enough with just a few additions.

[Edit: DarkGDK does look really handy, I'll look into that too...]

Yet another game programmer
Cash Curtis II
21
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 29th Jan 2008 11:50
How many elements does the array consist of? Is it always a set amount, or does it vary?


Come see the WIP!
Dewi Morgan
18
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 29th Jan 2008 13:08
Not sure what you mean by "the array" there - what array are you referring to? I am asking a general question about anonymous array passing.

For most cases (a sort function, an export-to-bmp function, etc) it would be constant for the duration of the sort, but arbitrary for each call. For others (import-from-bmp, etc) it will be zero on entry and dynamically sized on exit. For yet others (push, pop, splice), the size would be be dynamic on entry and would be altered by the call.

Yet another game programmer
Cash Curtis II
21
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 29th Jan 2008 13:58
It really depends on exactly what you're doing. There are many solutions that I use, but unless you're more specific about the application then all I can do is offer vague advice. If you want a blanket solution then I'd go with IanM's array pointers.


Come see the WIP!
Dewi Morgan
18
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 29th Jan 2008 14:40 Edited at: 29th Jan 2008 15:35
Vague advice is not a bad thing, and is always welcome. High level generics are much more useful in the long run than lowlevel specifics.

I'm thinking that making a DLL for hashtable-based associative arrays would be best. A little slower than regular arrays, but much more powerful. If people want uber-speed, they can write their own damn functions

For this, I am searching for public domain hashtable libraries. Does anyone have any suggestions? I've found a couple...

http://www.efgh.com/software/htab.htm
http://www.pomakis.com/hashtable/hashtable.c

So, functions I would like to implement include:
- Prettymuch all array functions in PHP per http://php.net/array - particularly the sorting stuff.
- Save/load.
- Append (option to overwrite or leave existing keys)
- Identity comparison (true if arrays are the same array)
- Comparison (true if arrays contain the same items at the same keys)
- Content comparison (true if arrays contain the same items in any order)
- Key comparison (true of the arrays contain the same keys)
- A "foreach" iteration thing, which either respects the last-used sorting method, or lets you specify one.
- Conversion to/from DBP arrays, memblocks, matrices, and string (and via memblocks, also bitmaps, images, sounds, meshes, and mesh deformations).
- Import from mysql

Are there any programming standards, best practices, guidelines or naming conventions to which I could/should try to adhere? Techlord's thread on this was all I could find. http://forum.thegamecreators.com/?m=forum_view&t=117232&b=1

(If I can pull this off, I'll try for perl-style regexes next, because I couldn't find any solution for that in the manual or forums either)

Yet another game programmer
Cash Curtis II
21
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 30th Jan 2008 00:08
Use LUA Unity or Barnski's LUA plugin, it should do what you want.


Come see the WIP!
Dewi Morgan
18
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 30th Jan 2008 21:02
Use LUA instead of DarkBasic, and call DB stuff from there? Then I have [url="http://blogs.msdn.com/oldnewthing/archive/2006/03/22/558007.aspx"]two problems[/url].

If I want to use some other language, I won't use LUA, I'll use C/C++. But first, I want to see how much I can accomplish in DBP.
From tomorrow I should have mostly free time. So I'll have a hund for array DLLs that do all the above, and if I can't find any, have a bash at making some myself.

Yet another game programmer
Cash Curtis II
21
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 30th Jan 2008 21:20
Quote: "Use LUA instead of DarkBasic, and call DB stuff from there?"

No, you would not do that.


Come see the WIP!
Dewi Morgan
18
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 31st Jan 2008 09:56
You're right, of course, I missed the important item in the feature list:

"-use Lua tables directly and easily in DBPro! (array with named indexing)"

Hrm. For user-created content, the usefulness of embedding LUA is large enough that I'll definitely check it out: thanks for the pointer!

And my freeness is pushed back a day, bleh

Yet another game programmer
SirFire
21
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 31st Jan 2008 11:12 Edited at: 31st Jan 2008 11:15
EDIT: nvm

_____________________
Windows Vista: Just say no.

Login to post a reply

Server time is: 2026-06-17 02:31:39
Your offset time is: 2026-06-17 02:31:39