Click here to Skip to main content
15,889,808 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Combobox in DLL Pin
Anu_Bala4-Jan-10 0:49
Anu_Bala4-Jan-10 0:49 
GeneralRe: Combobox in DLL Pin
Richard MacCutchan4-Jan-10 1:01
mveRichard MacCutchan4-Jan-10 1:01 
AnswerRe: Combobox in DLL Pin
Tim Craig2-Jan-10 13:03
Tim Craig2-Jan-10 13:03 
QuestionRestricting rights to delete a dynamic array ? [modified] Pin
doug251-Jan-10 12:35
doug251-Jan-10 12:35 
AnswerRe: Restricting rights to delete a dynamic array ? Pin
«_Superman_»1-Jan-10 14:33
professional«_Superman_»1-Jan-10 14:33 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
doug251-Jan-10 16:28
doug251-Jan-10 16:28 
AnswerRe: Restricting rights to delete a dynamic array ? Pin
Moak3-Jan-10 11:05
Moak3-Jan-10 11:05 
GeneralRe: Restricting rights to delete a dynamic array ? [modified] Pin
doug254-Jan-10 9:10
doug254-Jan-10 9:10 
Hi,

thanks for the suggestions.

I've actually decided not to change what i've done so i'm not seeking further help but I'll try to explain the situation better so you understand the conclusion I've come to since it's a bit more complicated than it may seem.

I'm sure the implementation of the container is ok and user friendly. The only issue is that memory for a member array shouldn't be deallocated by a user despite them having the permission. Although this shouldn't be a problem because someone probably wouldn't assume they should deallocate memory via a const pointer that's a member of a container class (correct me if i'm wrong) and anyone who's used a map or vector container should know it's not up to them to manage the memory for a map or vector's member variables. The container I've implemented is a specialised map and like a map it manages it's own memory. Since the array is declared protected I'm sure users would have the sense to check whether it's safe to manually deallocate the memory it uses and the function to retrieve the array has a const specifier in it's declaration which means memory can't be allocated for it, which should indicate to users that they shouldn't delete the array themselves I'm assuming.

What would totally solve the issue is if the C++ language (or compilers) made it so a dynamic array declared const couldn't be deleted. I don't see why it's possible to deallocate memory pointed to by a const dynamic array variable using delete while it's not possible to allocate memory for it using new. Ah because the address of a const pointer can't change but memory for a given address can be deallocated.

Basically the container I've made is a map that stores elements in a contigious array where it's possible to specify the order that they are stored in. I say array but it's actually a block of memory allocated with operator new and never new [] or new. The memory is always freed with operator delete. The reason for managing memory allocation for the "array" this way is so the calling of elements constructors / destructors is more controlled i.e. constructor is not called when inserting element, it's only called when inserting a new element and destructors are not called when the array is resized which makes it a very useful kind of container.

A vector wouldn't work because being able to retrieve a dynamic array manipulated by the container is a key reason why this container would be useful compared to standard ones. When I want to store elements mapped to keys and pass a customly ordered array of the elements to some other function that requires an array of maybe void* this container will be extremely useful. I don't want to go into too much detail but that's why I've implemented the container to use an array and not vector. A vector will call destructors of elements when it is resized and that's quite undesirable in certain cases.

If I understand correctly boost::shared_ptr wouldn't work because to access the array the way I need / intend would require dereferencing the pointer to it which would mean the variable retrieved would be in the same condition as what is returned by the Array() function at the moment. But I'm not sure what you meant by using a shared_ptr ?

Using a buffer passed by the user wouldn't be a practical solution because of the way memory is managed using operator new and operator delete by the container. For the container to work properly, it would basically require that the user never allocates memory for the buffer because the container also associates indices with keys so things would get a bit complicated. The user would have to only ever call operator delete on the buffer and let the container do the rest.

So my conclusion is that bearing with the mild (I think) issue that the array returned by Array() can be deleted is probably the most simple solution. The user only needs to know not to delete it, and i'm sure most users would assume that.
GeneralRe: Restricting rights to delete a dynamic array ? Pin
Moak4-Jan-10 12:01
Moak4-Jan-10 12:01 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
doug254-Jan-10 12:27
doug254-Jan-10 12:27 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
doug255-Jan-10 2:40
doug255-Jan-10 2:40 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
Moak5-Jan-10 3:41
Moak5-Jan-10 3:41 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
doug255-Jan-10 15:10
doug255-Jan-10 15:10 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
doug255-Jan-10 16:44
doug255-Jan-10 16:44 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
Moak5-Jan-10 23:16
Moak5-Jan-10 23:16 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
doug256-Jan-10 3:43
doug256-Jan-10 3:43 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
Moak6-Jan-10 12:51
Moak6-Jan-10 12:51 
GeneralRe: Restricting rights to delete a dynamic array ? [modified] Pin
doug256-Jan-10 16:14
doug256-Jan-10 16:14 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
Moak7-Jan-10 1:03
Moak7-Jan-10 1:03 
GeneralRe: Restricting rights to delete a dynamic array ? Pin
doug257-Jan-10 11:38
doug257-Jan-10 11:38 
Questioncommunication between objects Pin
Alex80gbg1-Jan-10 8:44
Alex80gbg1-Jan-10 8:44 
AnswerRe: communication between objects Pin
Rozis2-Jan-10 8:17
Rozis2-Jan-10 8:17 
GeneralRe: communication between objects Pin
Alex80gbg2-Jan-10 11:52
Alex80gbg2-Jan-10 11:52 
QuestionLNK2019 for XmlLite Pin
A&Ms1-Jan-10 8:30
A&Ms1-Jan-10 8:30 
AnswerRe: LNK2019 for XmlLite Pin
A&Ms1-Jan-10 11:14
A&Ms1-Jan-10 11:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.