Hello developers, I have currently the following problem: I want to use the SmartPointer with an array type datatype e.g. char[13]. The following contructors are implemented: 1.) SmartPointer () default constructor with empty payload 2.) SmartPointer (uint8_t size) Allocates memory from the given size. 3.) template<typename T > SmartPointer (const T *data) 4.) SmartPointer (const SmartPointer &other) The third variant is not useable with pointer type data, because the memory gets only calculated for the size of the pointer. So the next solution would be to use variant 2, but then there is no way to fill the data array. There are only getter functions and no setter functions. Thus i would suggest to add another constructor type template<typename T > SmartPointer(const T *data, int size) which allocates size*sizeof(T) memory. For this solutions also getter functions with a size parameter have to be added. The pointer is not type-safe anyway. If you can think up a better solution, please tell me. If you are ok with this solution, I will implement it as soon as possible. Best Regards, Thorsten Lajewski
Hello,
I have currently the following problem: I want to use the SmartPointer with an array type datatype e.g. char[13].
The following contructors are implemented:
1.) SmartPointer () default constructor with empty payload
2.) SmartPointer (uint8_t size) Allocates memory from the given size.
3.) template<typename T > SmartPointer (const T *data)
4.) SmartPointer (const SmartPointer &other)
The third variant is not useable with pointer type data, because the memory gets only calculated for the size of the pointer.
Are you sure about this? sizeof(char[13]) is 13 and different from sizeof(char*). None the less I don't think it would be the right solution.
So the next solution would be to use variant 2, but then there is no way
to fill the data array. There are only getter functions and no setter functions. Thus i would suggest to add another constructor type
template<typename T > SmartPointer(const T *data, int size) which allocates size*sizeof(T) memory. For this solutions also getter functions with a size parameter have to be added. The pointer is not type-safe anyway. If you can think up a better solution, please tell me.
I would prefer a separate array smart pointer. Since the access functions for objects and arrays are different, a new class would be the better choice than to add a second (and orthogonal) interface to the smart pointer class. Cheers, Fabian
On 07.01.2014 09:30, Fabian Greif wrote:
Hello,
I have currently the following problem: I want to use the SmartPointer with an array type datatype e.g. char[13].
The following contructors are implemented:
1.) SmartPointer () default constructor with empty payload
2.) SmartPointer (uint8_t size) Allocates memory from the given size.
3.) template<typename T > SmartPointer (const T *data)
4.) SmartPointer (const SmartPointer &other)
The third variant is not useable with pointer type data, because the memory gets only calculated for the size of the pointer.
Are you sure about this? sizeof(char[13]) is 13 and different from sizeof(char*).
Oh sorry, my reinterpret_cast was one byte to short for my Datatype, which destroyed my code there. You are right the SmartPointer is also working for arrays. Best Regards, Thorsten
_______________________________________________ xpcc-dev mailing list xpcc-dev@lists.rwth-aachen.de http://mailman.rwth-aachen.de/mailman/listinfo/xpcc-dev
participants (2)
-
Fabian Greif
-
Thorsten Lajewski