Faster Vector list... how?
-
On 21/04/2015 at 00:47, xxxxxxxx wrote:
Originally posted by xxxxxxxx
How does one use, say, BaseArray with my_spline->GetPoints()? Do you simply cast or does one need to copy the Vector* array into the BaseArray? What exactly? You guys continue to tout this stuff but where are the extensive usage examples? Even these types are well hidden in the API docs. And they are not used in the cinema4dsdk examples. One reason that I don't use them is there is no exemplification of their usage.
If you look at my reply you'll see that I recommended using the BaseArray instead of the manual array Rui used in his first example.
You'll have to use the pointers/manual freeing as long as we keep the API compatible (and it took some efforts to keep the changes you had to apply to your plugin code minimal - compared to what changed internally in recent years).
Keeping the API compatible for a very wide range of plugins however won't be possible till infinity (if you look in the past there have been bigger changes like going from float to double in the scene format that broke API compatibility).
Therefore my advice is: Avoid manual arrays in your code (whenever possible), make yourself familiar with the BaseArray (and it's derivations), understand the usefulness of C++ 11 move semantics and spend some time with iterators.
Regarding examples in the SDK: Searching for "BaseArray" reveals 13 occurrencies in the R16 SDK
- activeobject.cpp
- arraytutorial.cpp
- edgecuttool.cpp
- gl_test_object.cpp
- memstat.cpp
- menutest.pp
- misctest.cpp
- movecopyconstructors.cpp
- paintundo.h
- pgp.cpp
- sculptbrushmultistamp.cpp
- sculptmodifier.cpp
- snaptool.cppBest regards,
Wilfried
-
On 21/04/2015 at 06:16, xxxxxxxx wrote:
Originally posted by xxxxxxxx
oh, I wasn't aware of this "I guess I'm learning more about exceptions everyday "
I don't want to jump over the thread with my questions now, but I'm curious about 2 things:
1- I'm using a dll which uses STL very heavily , is this safe?
2- any suggestion of STL like containers library that doesn't use exceptions? "I didn't try Boost yet but I don't know if it uses exceptions or not".1.: Not it is not really safe. If you disable exceptions and STL try to throw one then you plugin will simple CRASH.
AFAIK std::vector will throw exception only on memory errors.
This is not that likely on 64bit system, but still possible.2.: Well the first chose would be c4d_misc::BaseArray and Co.
Boost is based on STL and of course uses exceptions.About GetPoints() and other such functions.
Most of them return pointer to memory that you do not Own so you do not need BaseArrayfor this. BaseArrayis need for arrays that you Own and responsible to free.In other cases you can use RAII types like AutoGeFree from "ge_autoptr.h" header file.
Remo
-
On 23/04/2015 at 14:56, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Well, my code is well behaved (I don't leave inbetween the new[] and delete[]) but I see your point.
How can you be sure about this ?
http://bromeon.ch/articles/raii.html
Remo
-
On 24/04/2015 at 01:46, xxxxxxxx wrote:
Because all my returns checks are performed before the creation of the arrays. In between the creation and deletion, there are no returns.
So, I'm pretty sure there are no arrays left hanging.
But, in the future, I will use BaseArray -
On 24/04/2015 at 02:31, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Originally posted by xxxxxxxx
oh, I wasn't aware of this "I guess I'm learning more about exceptions everyday "
I don't want to jump over the thread with my questions now, but I'm curious about 2 things:
1- I'm using a dll which uses STL very heavily , is this safe?
2- any suggestion of STL like containers library that doesn't use exceptions? "I didn't try Boost yet but I don't know if it uses exceptions or not".1.: Not it is not really safe. If you disable exceptions and STL try to throw one then you plugin will simple CRASH.
AFAIK std::vector will throw exception only on memory errors.
This is not that likely on 64bit system, but still possible.2.: Well the first chose would be c4d_misc::BaseArray and Co.
Boost is based on STL and of course uses exceptions.About GetPoints() and other such functions.
Most of them return pointer to memory that you do not Own so you do not need BaseArrayfor this. BaseArrayis need for arrays that you Own and responsible to free.In other cases you can use RAII types like AutoGeFree from "ge_autoptr.h" header file.
Remo
Also, you will have problems if you write to the std::vector in two different modules as they are
(especially in a C4D plugin) likely to use a different memory allocator. If you append to the vector
in your C4D plugin so that new memory must be (re-allocated) but the vector becomes destroyed in
DLL, it will most likely crash.-Niklas