There is function like MyFunction( T* apElements, int anCount );
As it can be seen it accepts an array as argument..
In my code, I have a pointer to array ( MyObject** ),
and I need to pass this array to the MyFinction...
If I write like followings in my code, does it becomes a costly operation? I mean, I do de-reference 'a pointer to array' to 'an array'; and the size of array is very large( e.g. 100.000 ); In this case how does 'de-referencing' behave ? Does it dereference all thousands of objects or something else ?
Originally posted by the one I mean, I do de-reference 'a pointer to array' to 'an array'; and the size of array is very large( e.g. 100.000 );
Not quite. T* as a type is just a pointer to T, it's not an array of T. So you have a T**, which is a pointer to a pointer of T, you dereference it and this will become only a pointer to T.
So the dereference operation only works on the pointer and hence it is quite fast.
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
Well, the difference is that with * you can have dynamic arrays at runtime, while you cannot do that with []. The only real danger is that you will have memory leaks or memory overwrites, but that's a common problem for c-style arrays.
If you are writing in C++, I strongly suggest you have a look at std::vector. A good place to start for this is Gabriel's introduction to vector
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
That's a great article that I will certainly be advising everyone to read. I absolutely agree: STL is both generic and fantastic, but it does have 2 major drawbacks: the documentation is dreadful, hard to find and hard to read; and the code is incredibly hard to read and debug. But that's the price you pay performance, I guess. Of course, you always have a good source of advice...
Some cause happiness wherever they go; others, whenever they go.
Bookmarks