Pages: 1
Author Topic: Idea for var  (29,289 Views)
Offline (Unknown gender) RetroX

Master of all things Linux
Contributor
Joined: Apr 2008
Posts: 1,055
View profile
Posted on: March 28, 2010, 03:10:56 AM
This is an idea that I had a while ago, and I'm assuming that it will be a lot faster than var:
mixed.hpp
types.hpp (has a lot of stuff that is not required for the above)

Unsigned char and char are treated as separate types to dictate which should be displayed as a character and which should be displayed as a number.

I use types.hpp for a lot, which is why it has loads of comments (mixed.hpp would have the same thing but I'm lazy right now).  I just made mixed.hpp in about ten minutes.

tl;dr for the code: it stores void *value and uint8_t type, the void pointer storing the value of the type, and the integer to decide which type that it is, as opposed to creating a separate value for double and string within a structure and returning whichever one depending on which is requested.
Offline (Unknown gender) serprex

Smooth ER
Developer
Joined: Apr 2008
Posts: 106
View profile WWW
Reply #1 Posted on: March 28, 2010, 12:20:47 PM
Why is this faster? There's too many types. GM is a two type system. struct{union{double d;size_t i;}char*s;} is the optimal type. Though struct{union{double d;struct{uint32_t i;uint32_t r;}}char*s} would be the way to go about refcounting. My version has unboxed doubles. So does Josh's. Yours doesn't. You're designing a smaller var, not faster
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #2 Posted on: March 28, 2010, 02:58:29 PM
I want the new var to offer casts to all scalars, optional overloads for iostream and fstream, and a copy-on-write system for arrays (allowing arrays to be passed as function parameters and script arguments).

To preserve speed, we sacrifice memory. It's always been that way with ENIGMA since I found a clue what I was doing. I thought of methods that would make var eight bytes, but I don't want to implement them as they waste instructions.
Pages: 1