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.

AppGameKit Classic Chat / Faster and more efficient data storage -- Bit-flags, Nibbles, Bytes, DoubleBytes

Author
Message
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 8th Aug 2018 14:48
While working on a project that uses large amounts of data, I decided to use bit flags, and such, to store more data in less vars. Greatly speeding up loading and lowering memory usage.

Attached is a sample project with all the functions I'm using, enjoy!

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Aug 2018 16:52
I don't see how it would be faster, and I suppose it could use less memory. But is there really any benefit when to set a nibble you call a function that takes 12 bytes of information passed to it?

Don't get me wrong, it's neat. I enjoy bitwise math. I'd see a greater benefit when storing map data, or when multiple flags can be set for the same action.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 9th Aug 2018 17:11
Phaelax I think he meant only faster loading the data in because it would be much smaller. Using it would definitely be somewhat slower.

I like the idea for flags as well and have done that kind of thing like you said for tile attribute flags etc.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 9th Aug 2018 17:25 Edited at: 9th Aug 2018 17:42
Suppose you are right there. The functions are a bit on the expensive side, could do without the range checks & multiplication. They might not perform so well in long loops. Though I learned a lot while working on them, I can refer to them while implementing optimized code.

The performance increase I noticed is with loading. I had several large arrays for map data, I was able to consolidate them into a single array. Which caused a considerable decrease in loading/setup time.

Just noticed I left a few "asdf" loop indexes in there.

Login to post a reply

Server time is: 2024-11-23 17:56:35
Your offset time is: 2024-11-23 17:56:35