Pointer to pointer array of scene nodes

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

Can't you make your life easy and use an irr::array or std::vector and just pass a reference to that?

edit: Also randomMesh's solution should also work with other pointers - even easier without casting. Just needs a second parameter for size which is generally better anyway - unless it's really not possible to pass in this situation.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

I´m just looking for an elegant and efficient method, the irr::array would add overhead just to overcome what seems to be an ISO compiler restriction.

I could cast the ILightSceneNode pointers to int pointers, and visaversa, that would would work, but...

Any idea why void * to array of void *´s isn´t allowed? I mean that seems such a simple and reasonable usage... right?

My code is working fine, it just would be good to know why these restrictions even exist!
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Pointer to pointer array of scene nodes

Post by serengeor »

robmar wrote: As the size of the array is related to the size of a memory pointer, which is the same for all things, can´t see why the compiler should not allow it for classes, or void ptrs, which is even stranger!
Seriously somethings wrong with the way you do it, it doesn't matter what type of pointer the array holds, it's a frickin pointer.
Post a minimal test case that fails so others can try compiling it and maybe fix it.

Guessing isn't fun anymore :wink:
Working on game: Marrbles (Currently stopped).
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Already did that, CuteAlien confirmed the error. See earlier.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Pointer to pointer array of scene nodes

Post by serengeor »

robmar wrote:Already did that, CuteAlien confirmed the error. See earlier.
You did not provide any compilable sample that produces the error(s)
Working on game: Marrbles (Currently stopped).
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

its in the posts: 2 lines of code.
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

I did? You mean the 2 lines where you mixed up array to pointers with pointer to an array? Those certainly can't be assigned to each other as they are different things. If that would compile the compiler would be broken!


But unless you _know_ (aka - you did profile it!) that using an irr::array reference instead really is the bottleneck in your application you simply shouldn't care about that. Or use the solution from randomMesh which looks _better_ anyway than passing a const array. I mean it's just 1 more parameter - unless this is really your absolute bottleneck which you absolutely can't have it's just not worth even having harder to read code in your application to avoid that!
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

well, working on the principle that in large programs it can me the hundreds or thousands of little inefficiencies that add up to create overall inefficiency.

Finally I used a different arrangement:-

irr::core::vector3df m_3dfLights[ MAX_LIGHTS ]; // Current location of active lights updated before each frame is drawn

vector3df (*m_pLights)[MAX_LIGHTS];

m_pGoochShader->m_pLights = &m_3dfLights;
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

robmar wrote:well, working on the principle that in large programs it can me the hundreds or thousands of little inefficiencies that add up to create overall inefficiency.
Usually doesn't work like that. If you do some profiling you will notice that usually you have at most a handful of lines which just dominate the profiling results. And once you get those bottlenecks removed your application speed will increase a lot while all the minor optimizations usually don't even show up. Although sometimes through profiling you might find out that what you thought would be minor thing isn't actually minor - and that is when you start working on such tricks.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Sure, I agree with you, but if you have code in loops like this, getting executed 60 times a second, and there are another 100 or 1000 items with inefficiency, it adds up.

Apart from that, I don´t like inefficient code, even small pieces of it, so I try to code efficiently and as elegantly as possible, which usually needs more time than I have.

This post was just to see if anyone knew how to resolve the pointer to array of ILightSceneNode pointers.

Unless I missed something, nobody has found a solution?...
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

Well... you got several solutions for the pointer to an array of ILightSceneNode pointers thing ... just not the pointer to array of constant size of ILightSceneNode pointers. Still don't know why you are not using randomMesh's solution which is better than using a constant array anyway. The second parameter?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Pointer to pointer array of scene nodes

Post by randomMesh »

Donald Knuth wrote:We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil"
"Whoops..."
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

I used to write device drivers in ASM, so my experience was without ISO type restrictions, and passing a pointer to an array of pointers wouldn´t have raised its ugly head! :)

I´m just curious to know why passing a ptr of an array of pointers, type void* or ILightSceneNode, should be prohibited in ANSI/ISO C++.

I don´t "need" to know, but I´d like to know!

I already have solved my original coding issue by using a ptr to an array of vect3df´s, so now its just an academic question.
CuteAlien
Admin
Posts: 9809
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

But you have 2 solutions already here which compile for the " ptr of an array of pointers". Just none for "ptr of an array with const size of pointers".
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

I´m just curious to know why passing a ptr of an array of pointers (with size constant), type void* or ILightSceneNode, should be prohibited in ANSI/ISO C++.
Post Reply