pouët.net

Easy lookup/access to members in "an array" of different datatypes if possible

category: code [glöplog]
You didn't get the question. What problem are you trying to solve with that array? What situation are you in so that you need an array that can store different data types?
added on the 2012-02-13 18:55:02 by kb_ kb_
problem with variables. to update whatever type of variables i need (later implement) without making copies. but to have access to them via pointers to be able to change them later.
added on the 2012-02-13 19:04:41 by rudi rudi
if that didnt make sense. try this:
the array has all the pointed variables.
they update in one call (or several function calls if there are separate arrays).
added on the 2012-02-13 19:11:20 by rudi rudi
it should be easy for me, but i mess up every time i try. having the idea, but not the expertise to actually code it. makes me mess with the wrong things.
added on the 2012-02-13 19:15:47 by rudi rudi
Ok, so you have this bunch of variables that do nothing in a program that does nothing, right?
added on the 2012-02-13 19:23:20 by kb_ kb_
Quote:

Why? Virtual function call:

- read pointer to vtable from object
- read pointer to virtual function from vtable
- call function
- return from function


The first 2 reads introduce 1 level of indirection, and higher chance of a cache miss. After that there's an actual call, which includes instructions to set it up, make the call, function prolog, function, function epilog and return.

Quote:

Switch method:

- fetch datatype variable
- read pointer from jump table
- jump to relevant case label
- jump to end of switch statement


As opposed to above, these first 2 reads are both likely to be cached and have greater locality. The 2 jumps that follow are probably relatively shorts, and depending on CPU type (and of course the data itself) benefit more easily from branch prediction; and the code has more locality in general. This all helps.

So I'd say that in the most favorable situation (this depends on CPU, implementation, memory layout and actual data in the array) it might be "somewhat" comparable. As soon conditions get less favorable the gap gets a lot bigger real fast. Multiply that by many entries et voila, a noticeable performance hit. An unnecessary one, because using a language "correctly" does not mean blindly applying the most "elegant" feature to each problem that seems similar on the surface.

And now on to Rudi's actual problem.. :)
added on the 2012-02-13 19:25:27 by superplek superplek
(it's probably my fault. Whenever I ask "what the fuck are you trying to code there" people always respond with technical details instead of telling me what the fuck they're trying to code. Must be me. Also reminds me of a certain network team that after months of discussion still didn't realize my point was that nobody gives a shit about RAID configs and virtual machine migration issues when the _actual_ problem was that the Partymeister server didn't work,)
added on the 2012-02-13 19:27:01 by kb_ kb_
kb_: hehe, right. they don't do anything. i think thats whats so great about the design, that they don't have to do anything at all really. i think they will serve a good purpose if it was ever pulled off, hopefully. maybe you have done it allready, but won't tell me because you don't know what the fuck i am asking for, if its advice or whatever, now when i start think of it i really dont know myself, what the hell i am doing, i dont know shit about compilers anyway

added on the 2012-02-13 19:43:10 by rudi rudi
Let me simplify the question even more. Rudi, you're making a computer program (or so it seems). What do you want it to do? Render a torus? Calculate the fastest route to Copenhagen?
added on the 2012-02-13 19:47:31 by superplek superplek
plek: yes to the first, no to the last. im not interrested in Copenhagen routes unless i didnt know the way if a demoparty where held there. but i wouldnt use this shit for that kind of thing anyway.
added on the 2012-02-13 19:49:48 by rudi rudi
What we're trying to find out is what you *are* using it for, and if just perhaps, there is another way that would prevent the need for this specific type of datacontainer -- or perhaps allow for a somewhat similar but more limited and efficient solution.

I really can't make this any clearer.
added on the 2012-02-13 19:52:15 by superplek superplek
and no its not what this shit is supposed to do. its mere like a: i create what i want to make, i don't calculate any routes or anything like that, its not what this particular bird is designed to do.
added on the 2012-02-13 19:53:52 by rudi rudi
I give up, this is like talking to a brick wall. A brick wall with autism.
added on the 2012-02-13 19:57:59 by superplek superplek
plek: im not sure how i can say it in other words. it really is what ive just said the few times.i really really need pointers to variables from the runtime, all at a particular point in time. is it hard to understand? :P
added on the 2012-02-13 19:59:32 by rudi rudi
As a coder i would like to read/write data of varying nature from the same dataset in order to be able to serialize/deserialize easily.

... That could've been one way of setting the scene ;-)
im just off to get some food. fuck you plek for that last comment!
added on the 2012-02-13 20:05:04 by rudi rudi
rudi, i'm completely impressed you're able to type c++ that passes a compiler at all.
added on the 2012-02-13 20:06:27 by skrebbel skrebbel
comedy gold <3
added on the 2012-02-13 20:12:13 by thec thec
rasmus: Yeah, but it's probable that the problem is of a different nature and thus allows for a completely different solution than the one that has been discussed so far. But if someone is unable to even simply state what kind of program he is making (my idea, after KB failed to get it out, was to narrow it down from there).. :)

Also Rudi, fuck me all you want, my comment was blunt, but it's really rude to waste people's time with questions you seemingly don't want the answer to.
added on the 2012-02-13 20:13:31 by superplek superplek
happy troll is happy :)
added on the 2012-02-13 20:14:43 by kbi kbi
guys:
no1 needs such an implementation, atleast not in a demo!
so i am really wondering how this troll-thread could grow that big that fast! ;)

[insert_random_lobsterAttack_here]click-clack[/insert_random_lobsterAttack_here]
plek: as i said earlier. my head... tired today. you should be lucky i comment reply on anything at all this evening.
i am not rude, i am very happy people choose to reply and have discussions which they have. everything i take into account when i read and for my design-choices, i appreciate, as long as i can understand them, but i dont appreciate someone like you telling that i am rude wasting other people's time.ppl choose what the fuck they want to use their time on.
added on the 2012-02-13 20:36:37 by rudi rudi
Quote:
you should be lucky

we should be lucky that we're allowed to answer your awesome question?
The question is: Why dont you code proper data type classes (e.g. Vector3f), write/overload their "add" or "+" operator function and throw that shit into an std::vector. Doesn't stop you from using pointers too...
added on the 2012-02-13 20:47:27 by raer raer
First of all, thanks for all the comments on my (on the first look) not so smart design. I did this for a small VM bytecode interpreter, where I had an opcode char array and the opcode data floating point array.

My floating point data is indeed all packed together, since all the data pointers (float*, vector*, whatever*) later point to a different position of the one large floating point data array. First of all come all floats, then all vectors, then all whatevers. If I used a union I would indeed increase the size of the struct in an unreasonable way, not so cool for sizecoding and small interpreter code anyway. So please, point me out again why "I'm doing things wrong"?
added on the 2012-02-13 20:51:31 by xTr1m xTr1m

login