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.

DLL Talk / The Matrix1Utils plugins collection

Author
Message
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Jul 2006 23:30 Edited at: 25th Aug 2021 11:29
Newest release 27/05/2012



We're now up to 33 plug-ins in this pack - latest release info can be found HERE (Release 20120527).
Download links can be found at the bottom of this post.

In addition, I've uploaded the help files to my website, so you can browse through all of the commands, so you can see what you'll be getting without having to install the whole thing first. Just click here to see them.

01 - Memory Banks - memblocks, with a few new options added
02 - Basic Timing - Metronome type ticking, and hiresolution timing.
03 - Mutexes - system level synchronisation between processes (primarily for use with shared-memory banks)
04 - Raw Memory & String Allocation - low level stuff only of use to masochists
05 - Find Free ... - locate free images, objects ... everything really
06 - Error message control - Take a little control over DBPro error messages, or even trigger your own (with a line number!)
07 - General functions - min/max, plus a few numeric functions that are missing from DBPro
08 - Random numbers - Many different random number generators.
09 - Functions and commands that should have been in DBPro from the start.
10 - Logging - Output logging info from your app, in nicely formatted html or rtf if you want to.
11 - Console window, with colours
12 - Limb information and updates
13 - Desktop & window info + manipulation
14 - Adhoc 'doesn't fit anywhere else' commands
15 - Extra WAIT commands - including system-friendly versions that use no system time
16 - Strings - A comprehensive set of string functions.
17 - 64 bit bitset manipulation - DBPro binary functions don't work with double integers, these functions do
18 - Create custom objects from nothing and get information about the state of objects.
19 - List and group objects
20 - Function pointers
21 - Zone commands, transferred & updated from the original utility plug-in.
22 - File I/O
23 - Colour conversion
24 - System Folders
25 - Windows shortcut files
26 - Syncs and callbacks
27 - Hashing (and encryption in the future)
28 - Networking for IP and UDP (tutorial zip file)
29 - Arrays - Information from arrays, plus sorting, clearing etc.
30 - Basic 2D Commands
31 - String lookup tables (with load/save of ini files).
32 - Vector & Matrix maths - Some commands and functions to make using the 3d maths commands a little easier.
33 - Redirect drawing operations to images


The release is a zip file for easy installation - just let winzip extract it to your DBPro installation folder and it'll all go into the right place.

DBPro 7.1 download and later : https://forumfiles.thegamecreators.com/download/2355306
DBPro 7.0 download and prior : https://forumfiles.thegamecreators.com/download/1599357 (No longer updated)

If the DLLs fail to load, then you may need the files in the following download:
VC++ redistributables : https://forumfiles.thegamecreators.com/download/959271

- For 32 bit systems, place the contents in c:\Windows\System32
- For 64 bit systems, place the contents in c:\Windows\SysWOW64
- Alternatively, if you are uncomfortable placing these files in those folders, or if you don't have the correct permissions to do so, place the files in the same directory as your executable.


If you have any of the original Matrix1Utility, Matrix1Array or Matrix1Extend1 plug-ins, then you'll need to delete the DLL's and the INI files for them before starting up DBPro.

Please also note: I have not ported any of this code to GDK, and these plug-ins will not work with GDK whatsoever

Warranty: None, for any purpose whatsoever.
Conditions of use: None.
Royalties required: None.

</div>
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Jul 2006 23:55
Memory banks - expanded memblocks.

For any kind of manipulation of data, you'll soon start to wonder how you did without them. In addition to the standard ability to write different basic data types to the banks, you can also:

- write double integers, double floats and strings too
- copy blocks of data between banks or even memblocks
- share memory between different programs
- map a file into memory (effectively load a file into a bank, but any changes you make are reflected in the file).

A long while ago, I wrote a function that would allow you to write a DBPro bitmap to a bmp file using standard file functions. I've written a small program that uses that function, but also does the same thing using a mapped file - run it yourself to see the speed increase:



For free Plug-ins and source code http://www.matrix1.demon.co.uk
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jul 2006 00:01
Timing - simple tickers

There's not much in this plugin really. There's the standard hi-resolution timer that was a part of the original utility plugin, and that works in the same way, and now there is also a regular ticking timer that ticks as often as you tell it.

Here's a simple example with two tickers - one is used to drive the flashing cursor, and the other is driving the tenth-of-a-second timer



For free Plug-ins and source code http://www.matrix1.demon.co.uk
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jul 2006 00:12
Error messages

There's not much to say here really (despite this being a real ... hard nut to crack) - error messages, with line numbers. You can trigger your own messages, change the title on DBPro error messages, even trigger messages under certain conditions. Here are a few examples.

As basic as it gets:


How about this:

Error 502 is 'image does not exist' - the numbers can be found in C:\Program Files\Dark Basic Software\Dark Basic Professional\Compiler\lang\english\Errors.txt in the RUNTIME section

Setting a 'reasonable' title for a DBPro error:

Ok, so we may differ in our opinion of 'reasonable'

Finally, error under certain circumstances - in the C world this is called an assertion, in which the error does not occur if the condition is true.


I'll post a few more things tomorrow

For free Plug-ins and source code http://www.matrix1.demon.co.uk
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jul 2006 16:01
Here's a full program that I wrote to automatically generate the help and keyword files for all of these plugins, and to demonstrate their use. It mostly uses the banks and string plugins and features:

- Correctly splitting up the command line arguments when dropping files onto the exe
- Reading/writing whole files in a single set of operations
- Reading resource strings from a DLL (used to get all of the commands for the keyword files)
- Complex and fast string manipulation

There are also some little 'bonus' routines in there for dealing with filenames and directories.

Attachments

Login to view attachments
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jul 2006 16:08
Here's another one for banks ... they really are my favourite!

In last months newsletter, Rich included a section on the Winch's site that includes details of the makeup of a DBPro executable or .PCK file. I decided that would be a good test of banks, so I wrote the following program that will decipher the exe/pck, list all of the files included within it, and will then explode it out into the separate files.

There's no reverse process ATM, but that may come in the future.

Attachments

Login to view attachments
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jul 2006 16:57
The logging plugin might look a little inpenetrable at first sight, so here's a small example program that writes out a html format log file.

You can also see the parameter substitution it provides when it's writing log file types 3 and 4.



Bmad6
19
Years of Service
User Offline
Joined: 25th Aug 2005
Location: Virginia, United States
Posted: 2nd Aug 2006 08:24
Only one suggestion - in part 13, the get display width() command (and others, I assume) interfere with the same command from the DBPro Enhancements Pack. Maybe add a prefix or something?

Other than that, though, this looks awesome!

Programming is the art that fights back.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Aug 2006 10:06
Thanks for pointing that out - I'll change the command and repost it later today

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Aug 2006 11:39
Nice little package I'll be replacing my own debug function with your logging, much neater.

The GET DISPLAY WIDTH() is a throwback to the last version. I ventured into the world of string tables for the first tme to edit this last time.



spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 2nd Aug 2006 12:31
Am I right in saying your new ABS command completely takes precedence over existing ABS command. Surprised not to see some sort of duplicate command error that I've seen in the past.

Anyway your ABS command is SO much faster than built in ABS command which is renowned for being so slow so I'm happy.

Too busy to try rest of commands, must get back to work.

Boo!
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 2nd Aug 2006 13:46
His string commands are wicked fast on slower machines. Been waiting for this for a bit

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Aug 2006 15:07
@Spooky,
Lee provided a ABS command for floating point values - that's why it's slow with integers as it has to convert integer to float, then float back to integer for the result. I've just provided an integer-specific version. It's OK to provide overloaded versions of existing commands and functions in plugins as long as their signatures are different.

@Bmad6 & Batvink,
I'll probably just drop the 'GET' at the start of the name to remove the clash.

sneaky smith12
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 2nd Aug 2006 18:37
hmmm... when i run the program i always get a

Then it lists several locations one including autodesk which doesnt make sense, because I don't have any autodesk products.

If at first you dont succeed, LOWER YOUR STANDARDS.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Aug 2006 19:11
Ah, the old 'runtime library' problem huh?

Here they are for use with the plugins - Just drop them into \Windows\System32 - If you already have these files installed in your machine, do not allow them to overwrite existing ones.

@Everyone else,
I've replaced the zip in the first post with the modified '13' DLL - I've simply removed 'GET' from the start of all of the functions. Just follow the install instructions again and allow the new files to overwrite existing files.

Attachments

Login to view attachments
John Y
Synergy Editor Developer
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: UK
Posted: 2nd Aug 2006 21:33
This is a really cool collection of commands. Thanks!

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Aug 2006 23:32
Thank you.

Here's a simple example of using the bitset commands.

The code that a lot of people use to detect a mouseclick is usually a little ... clunky (using bit manipulation) ... or even plain wrong (using straight comparison).

Instead, you can just treat the value of MOUSECLICK as a bitset, and interrogate the values by key number:


There are other uses too. For instance, in a piece of code that I'm performance testing right now, I can enable and disable various bits of code depending on which bits are set, and I can do it even when the code is running.

Here's a little taster of how that works:


Yes, it could also be done using indivually named global variables, or using an appropriately sized array too.

This way uses less storage which can be useful when writing to a file, or storing in a memblock or memory bank. A single bitset is also easier to pass around your program, seeing as it is basically just a standard variable.

Bmad6
19
Years of Service
User Offline
Joined: 25th Aug 2005
Location: Virginia, United States
Posted: 2nd Aug 2006 23:51
or:



Programming is the art that fights back.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Aug 2006 00:11 Edited at: 3rd Aug 2006 01:31
I know - I posted that code only a week or so ago, and a lot of the less learned coders on the forums wouldn't even know why it works.
Besides, it's quicker this way



[edit]Quick update to the plugin 17 - It wasn't handling the full 64 bit range correctly - now it is.

Grismald
21
Years of Service
User Offline
Joined: 4th Mar 2003
Location: France
Posted: 26th Aug 2006 13:40
Just wanted to say thanks for these great dlls.
I am making a snippet to write text files using memory banks mainly to see if i can get some speed improvements over using standard file functions; it's not fully working yet, but here's a link anyway:
http://forum.thegamecreators.com/?m=forum_view&t=86495&b=6
(see 2nd post)

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Aug 2006 22:02
Thanks. I've made a post in your thread that may help you get the speed increase you are after.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Oct 2006 02:45
Here is a new update, including one semi-experimental new plugin that allows DBO objects to be loaded from a memory bank.

Matrix1Util_01 1.0.0.2
Added 3 SEARCH BANK functions to allow string searches within banks.
Added 2 ZERO BANK commands to clear banks or areas of banks.

Matrix1Util_07 1.0.0.2
Added GCD functions (greatest common denominator)
Added integer and double version of the clamp and wrap functions

Matrix1Util_12 1.0.0.1
Initial public release (GET LIMB BY NAME, GET LIMB COUNT, GET LIMB FVF)
Added SET LIMB NAME command
Added GET LIMB PARENT/CHILD/SIBLING functions

Matrix1Util_13 1.0.0.2
Added HAS FOCUS function and GRAB FOCUS command.

Matrix1Util_16 1.0.0.2
Faster string-length function for a general speedup throughout.
Fix bug for positional checking in the GET SPLIT WORD function.

Matrix1Util_17 1.0.0.2
Faster bit count routine.

Matrix1Util_18 1.0.0.1
New plugin that allows objects to be created from memory banks.
They need to be .dbo format.

Attachments

Login to view attachments
Olby
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 11th Oct 2006 00:55 Edited at: 11th Oct 2006 00:58
Ian you rock this place mate!

"Error at line 0 - Your game sucks. Try again loser..." (Cash Curtis II)
AMD Sempron 3.1+ Ghz, 512MB Ram, ATI R9550 256MB Ram, Sound Blaster Live!, WinXP SP2, DirectX 9.0c, DBP 6.2
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Oct 2006 13:40
Thanks.
Have a 'fix' release.


Matrix1Util_13 1.0.0.2
Corrected help files - added 'GET' to all infomation functions

Matrix1Util_18 1.0.0.2
Corrected 'offset' version of the MAKE OBJECT FROM BANK command
Removed need for the fourth argument too as DBO knows how far it can go

Plugin 18 is no longer experimental - it works just fine every time.

Attachments

Login to view attachments
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Oct 2006 13:45
Here's an example of multiple DBO objects being loaded from a bank. It uses the new bank functions to search for DBO objects and loads them.

It's a little involved, but bear with it.



cjb2006
18
Years of Service
User Offline
Joined: 20th May 2006
Location:
Posted: 14th Oct 2006 17:30
IanM, I am in awe. Great work. In my current project I'm working with x-files. I understand they are slower but it's easier for this human to parse a .x text file. Is it possible for you to add a "make object from bank" command for a text .x file to the collection? A kind of "Load mesh"=>"Make object" command from a virtual file (bank). I know I sure could use it but if I'm the only one, then it's no biggy. Thanks for all you've done already.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Oct 2006 22:56
I've been looking into it since you posted, and there doesn't seem to be an easy way ATM. I won't give up on it though - I'm sure that it can be done.

In the meantime, you can use DBPro to load your x models and save them back out as a dbo file if you want to take advantage of the new command.

When I do figure out the loading of x files from a bank, the same code will be able to load the data without you needing to give it any clues beyond the start position.

cjb2006
18
Years of Service
User Offline
Joined: 20th May 2006
Location:
Posted: 21st Oct 2006 17:13
Hey, thanks for looking into it. I'm basically working on a custom model editor - adding / deleting verts, flipping edges etc. on the fly. I can keep track of that stuff fairly easily in a .x text file. I can use a bank to write the file but it would be nice to not have to re-read it for each model update (since it's already in a bank). Keep up the good work, and thanks again.
ThomasFN
20
Years of Service
User Offline
Joined: 26th Aug 2004
Location:
Posted: 27th Oct 2006 21:45
any advanced matrix functions about? (ie colour individual verticies on a mtx, apply a texture to the whole matrix rather than just a tile, detail texture blending, tile border blending)

Olby
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 29th Oct 2006 02:34 Edited at: 29th Oct 2006 02:36
@IanM - I have probably found an error (what else I can do?), when I call find free memblock() some times I get the memblock id is out of range. So I guess your limits are incorrect. It only happens occasionally because I use random free memblock finding. I tried to lower the value to find free memblock(1,100) then everything worked fine. I dont know but maybe the maximum memblock count is 128?

[Edit]
Did I already told you that these are very good and fast plugins! And Im currently building my FPS engine around these.

AMD Sempron 3.1+ Ghz, 512MB Ram, ATI R9550 256MB Ram, Sound Blaster Live!, WinXP SP2, DirectX 9.0c, DBP 6.2
http://www.myspace.com/producerolby
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Oct 2006 13:17
@ThomasFN,

I don't think that kind of functionality is available for matrix's - you might need to use standard objects & limbs for all of that. You can search in the Code Snippets forum, or in the code base for example code.

I may add something like this in the future.

@Olby,

I can't find any error with the FIND FREE MEMBLOCK code. Are you remembering to check for a returned value of 0? If you do get 0, then you've already used up all of your memblocks.

If you have any example code that exhibits this problem, then just post it here or email it, and I'll take a look.

ThomasFN
20
Years of Service
User Offline
Joined: 26th Aug 2004
Location:
Posted: 29th Oct 2006 14:24
Thanks for your help, IanM. I may use an advanced terrain and used vertex data and limb stuff to do what i want.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Nov 2006 10:51
Cool, I needed that parent limb function

Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Nov 2006 13:28 Edited at: 2nd Nov 2006 13:31
Some very handy commands here Ian

I have been trying a few but have come across one that doesn't work 'as advertised'.



That code brings up this error:
Cannot perform 'integer' cast on type 'TEMP2' at line 10.

Is there any chance you could have a look at this? It would be very handy.

Thanks

[edit] Same problem with REMOVE ALL$

Bmad6
19
Years of Service
User Offline
Joined: 25th Aug 2005
Location: Virginia, United States
Posted: 2nd Nov 2006 14:01
Scraggle, I'm surprised you didn't catch this error!

That error message means that it's trying to store String data in an Integer variable. either replace tS w/ t$ or put tS as integer above this code. (I assume you meant to do the former from the start.)

Corrected code:



And I ran it, to check.

Windows XP Home Edition SP2, Intel Celeron 1.4 GHz Processor, 768 MB of RAM, 1024x768 Srceen Resolution, NVidia 256MB FX5200 GPU
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Nov 2006 14:16 Edited at: 2nd Nov 2006 14:17
Now I feel stupid!

Sorry Ian for assuming it was a problem with your plugin-in and thanks to Bmad for pointing out my stupidity

... and yes, I did mean to do the former from the start.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Nov 2006 14:39
No problem - I generally spend quite a bit of time on testing these before I release to avoid being embarrassed later, so I was surprised to see your post. So far, only 2 bugs found in these plug-ins, and one of those I found myself

Thanks to Bmad6 for finding the problem.

Olby
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 19th Nov 2006 16:00
I found another bug with split string$.

Check this...


It splits string not using all delimeter string " -" but uses just first which is just a space.

Even if this is not a bug adding this functionality for more than one char in delimeter string would be awesome.

AMD Sempron 3.1+ Ghz, 512MB Ram, ATI R9550 256MB Ram, Sound Blaster Live!, WinXP SP2, DirectX 9.0c, DBP 6.2
http://www.myspace.com/producerolby
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Nov 2006 17:52
Sorry, but that's not a bug - the second string is used as a list of single character delimiters. If you want to search for string delimiters, then a simple way to do that would be to REPLACE ALL of your delimiters with a single character, then SPLIT STRING using that character.

Also, if you check out the HelpGen code in one of my earlier posts, you'll find that it contains a source file 'CommandLine.dba' which takes the command line and splits it correctly.

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 20th Nov 2006 14:22
just wanna say that im using your plugin for the timer functions . its fast , thanks man
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Nov 2006 19:18
Thanks - if you can think of any additions, let me know.

Olby
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 21st Nov 2006 21:01 Edited at: 21st Nov 2006 21:28
Stupid me I never thought about that I can do it the other way. Thanks Ian, by the way I use almost all of your extension plugins, my favourite are free ID finders, timers and text 'snippits'.

AMD Sempron 3.1+ Ghz, 512MB Ram, ATI R9550 256MB Ram, Sound Blaster Live!, WinXP SP2, DirectX 9.0c, DBP 6.2
http://www.myspace.com/producerolby
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Dec 2006 17:15
I don't think it's possible at the moment, but can you make it so that you can expand banks or memblocks. Sometimes, I need to make a memblock before I know the maximum amount of data I'm going to put in!

I know I could make a new bank, and copy across the contents, but wouldn't that be too slow?

Also, an efficient way to turn an integer/float into a string and back again would be very useful. (eg. turning it into a four char string) This would remove the need for delimeters in a string, as it would always be four chars long!

PS great plugin!

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Dec 2006 18:47
Quote: "expand banks or memblocks"


Difficult, but doable - the problem is that expanding a bank without copying data would slow down the general access of that bank, and I'd rather not do that. Give me a while to think about it and I might be able to come up with something that wouldn't affect speed unless you are using an expandable bank. No promises, and I reserve the right to come up with something completely different

Quote: "Also, an efficient way to turn an integer/float into a string and back again"


You can use the STR$ and PADRIGHT$ functions to convert to a string and to expand the string up to the number of characters required by padding with trailing spaces (not leading zeros, because of negative numbers). Then use the VAL or INTVAL to translate back to the original value.

Alternatively, just stick with delimiters and use the SPLIT STRING command. It's actually very fast - probably faster than extracting the string yourself.

In the meantime, I'll try and come up with a more general system for formatting that's not too restrictive.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Dec 2006 19:46 Edited at: 21st Dec 2006 19:46
Thanks for replying quickly, but about my second point:

If you use str$ and val, thats fine and works, but it must be much slower than directly reading a string from a piece of memory written to using an integer or float. Also, -932514832.5 would take up only four bytes, rather than 12 plus the delimeter, which makes 13.

Also, just now, I am having a problem with this:
size = fast len(lines(sel))

however, this works:
size = len(lines(sel))

size = 0 `integer
sel = 0 `integer
lines(sel) = "" `string

There is no error message, just the box saying blahdiblah has performed an illegal operation, and must now close.


For the moment, I'll just use len(), but it's annoying all the same...

Thanks in advance for any help you give

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Dec 2006 21:37
Hey, thanks for the bug report - I will re-release the plug-ins soon so that you can have the fix. In the meantime, you can continue to use the FAST LEN function by ensuring that your strings are properly initialised

This will fail:


This will work:


and so will this if you can't ensure that all strings are correctly initialised:


... basically there is a difference in DBPro between an uninitialised string and an initialised one. FAST LEN doesn't take account of this.

Now regarding what else you said in your post ... well, I'm confused. You said:

Quote: "-932514832.5 would take up only four bytes, rather than 12 plus the delimeter, which makes 13"


Are you saying that you want to store integers and floats within strings in binary format? If so, then you can't unless you encode them in some way, because if any of the bytes of the value equate to 0 then that will corrupt your string. The best that could be done like that would be to use 4 bytes and 4 bits - if that's what you mean, then I'll be happy to help with the encoding.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Dec 2006 23:12
Thanks, I thought that strings were just a couple of bytes for the length, then length many bytes for each character. I didn't realise that they were ended with a 0 byte.

Anyway, I'd still much rather have 5 bytes rather than 13

Also, instead of having to encode it, you could shorten the dword length to 0 ... 4228250624 which would fit into four bytes, although I'm sure your way is better

I'm getting VS.net 2005 this christmas, so then I'll be able to make some simple functions of my own

I thought that doing: a as integer was defining a variable properly Oh well

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Dec 2006 23:27 Edited at: 21st Dec 2006 23:43
It's only a problem with strings. Initialised strings have a pointer value that points to a 1 byte array containing a terminating null. Uninitialised strings have a pointer value of 0 - when the 0 is referenced as a pointer, you get the crash.

Your maths is wrong on the dword. You can't have a 0 value, or 256, or 65536 or 65792 (and so on). Basically, instead of the range being 0 to 4294967295 (256^4-1), it will be 4228250624 (255^4-1) with extra care taken that none of the individual bytes contain a zero value.

[EDIT] DOH! That's me not reading your post properly - you're right of course. [/EDIT]

Floats would be slightly harder because you can't use bit manipulation on them directly and you have to take care where you lose the precision.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Dec 2006 10:41 Edited at: 22nd Dec 2006 10:42
I just made my own function that turns an integer or dword to a string, and then back again

Also, I just found out by doing this, that when the first bit of an integer is 1, it means it's negative. That means that it goes 0 ... 2147483647 then -2147483648 ... -1
Positive integers have the same bits as their equivelant in dword format.

I wonder why they don't just go -2147483648 ... 2147483647

Here is the code that does it:


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Dec 2006 16:25
Quote: "I wonder why they don't just go -2147483648 ... 2147483647"


2's complement binary maths ... let's just say that it's easier to do in hardware.

Nice use of the bits plug-in, but as you are dealing with 32 bit numbers you can use DBPro's built-in binary manipulators and use simple shifts, masks and or's.



Just wrap the encode in a STR$ and the decode in a INTVAL to put it in a string.

Floats will be different again, as instead of losing bits 27 to 30, you'd be best to lose bits 0 to 3. You can get the bit pattern of a float by using a memblock - write a float, read a long, and do the reverse to get back from a long to a float.

Login to post a reply

Server time is: 2024-11-21 09:27:14
Your offset time is: 2024-11-21 09:27:14