BaseSelect - ToArray() and FromArray()
-
On 23/04/2014 at 10:45, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14
Platform: Windows ;
Language(s) : C++ ;---------
Hi,I was attempting to store BaseSelect selections using BaseSelect->ToArray() and BaseSelect->FromArray().
I was then storing the resulting UCHAR pointers inside a c4d_misc::BaseArray<UCHAR> selectionsArray.
This seemed to work in effect, but the problem i had was that the values i was getting when casting the UCHAR pointers back into BaseSelect using FromArray() were never what i`d stored using ToArray(). The actual GetCount() of the resulting BaseSelect seemed to vary in size also..
So i ended up just storing my selections as a list of Bool values inside of BaseArray as it was easy to implement, fast enough, and predictable.
Has anybody else had this sort of problem with ToArray() and FromArray() or have i been doing something wildly wrong?
-
On 23/04/2014 at 14:53, xxxxxxxx wrote:
Please note that BaseSelect::GetCount() will only return number of selected (True) elements.
But BaseArray::GetCount() will return total number of True and False.
By the was most memory efficient way to store True/False values it only to use 1bit for every value
For example in STL there is std::vector<bool> for this, or std::bitset also.
But of course it is also possible to create one based on c4d_misc::
BaseArray. -
On 23/04/2014 at 15:22, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Please note that BaseSelect::GetCount() will only return number of selected (True) elements.
Yes, i know..
Originally posted by xxxxxxxx
But BaseArray::GetCount() will return total number of True and False.
Yes, i know..
Originally posted by xxxxxxxx
By the was most memory efficient way to store True/False values it only to use 1bit for every value
For example in STL there is std::vector<bool> for this, or std::bitset also.
But of course it is also possible to create one based on c4d_misc::
BaseArray.Yeah i know.. I`ve been using c4d_misc::BaseArray<Bool> to store the selections. Actually, the code i have been using ( because it is a variety of different selections ) is roughly:
c4d_misc::BaseArray<c4d_misc::BaseArray<Bool>> selectionsArray;
So basically, an array of Bool arrays..
-
On 24/04/2014 at 02:52, xxxxxxxx wrote:
c4d_misc::BaseArray<c4d_misc::BaseArray<Bool>> selectionsArray;
> So basically, an array of Bool arrays..
No, please no
Use array of array only if you really really need this, for dynamic 2d arrays or something like this.I meant another array class that uses BaseArray of Int32 where you store 32 Bool in every value.
Of course to make this you will need to use bit shifting, so it may be not easy to implement.Second most easy way to store Bools that consumes 8x memory is of course to use UCHAR (Int8).
There is not optimized template specialisaiont of c4d_misc::BaseArray<Bool> for Bool, like there is one for std::vector<bool>.
On the other side std::vector<bool> has some drawbacks too, so not everyone recommend to uses it. -
On 24/04/2014 at 04:03, xxxxxxxx wrote:
Okay, now you`re giving me something to think about
Is a BaseArray of BaseArrays a bad idea, for memory reasons or speed?
Just learning C++ so this info is useful..
So you are talking about storing a BaseArray of Int32 with the Bools ( ie 0
s and 1
s ) stored in groups of 32? Ie if i have 400 polygons id have 400/32 Int32
s inside an array? -
On 24/04/2014 at 06:51, xxxxxxxx wrote:
Is a BaseArray of BaseArrays a bad idea, for memory reasons or speed?
For both, memory and speed.> So you are talking about storing a BaseArray of Int32 with the Bools ( ie 0
s and 1
s ) stored in groups of 32? Ie if i have 400 polygons id have 400/32 Int32
s inside an array?
Yes kind of, you will need 13 In32 for this.But if you only learning C++ and do not need the last bit of speed and memory optimization,
just usec4d_misc::BaseArray<UChar>
for this.
It is much more easy to use.But if you want to learn more, here are probably not the best links with some extra info for this.
http://www.codeproject.com/Tips/53433/BitArray-in-C
http://stackoverflow.com/questions/3806469/bit-array-in-c
http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html -
On 24/04/2014 at 08:12, xxxxxxxx wrote:
Thanks for the info Remotion - it`s much appreciated.
Yeah i
d rather optimise for speed as much as possible, as the plugin i am developing is quite intensive. I
m learning C++ as i said but quite familiar with programming in general, so the main thing is getting to grips with different types and how to apply them. And same for the C4D types within the APIAs i said in my initial post, i was using BaseArray<UCHAR> but was having trouble with the FromArray`s coming back as different sizes/values to what i was storing.. So i eventually gave up and moved over to storing lists of bools..
It could have been some scope issue, but i even tried storing my ToArray() uchars and retrieving them directly after for testing, and same problem..
Will possibly try a clean test outwith the code i`m working on and see how that goes.