|
Have a look at series of articles about shell extensions by Michael Dunn[^].
|
|
|
|
|
I have staring at my code for an hour now thinking of a suitable way to overcome this problem.
I have a class ( classA ) which has a static std::list of struct ( containg a classB pointer ) pointers as a member. The purpose of classA is to map any derived classes to an instance of classB depending on certain paramaters. Within the struct is a reference count of all the derived classes which are using an instance of classB.
class classA
{
typedef struct tagBATCHMAP
{
DWORD VertexType;
DWORD_PTR Texture;
classB* Batch;
UINT RefCount;
} BATCHMAP, *LPBATCHMAP;
public:
static void DeleteAll ( void );
static void CollectGarbage ( void );
protected:
classA ( void );
virtual ~classA ( void );
bool AddBatch ( DWORD dwType, DWORD_PTR dwpTexture );
UINT Release ( void );
private:
bool CreateInstance ( DWORD dwType, DWORD_PTR dwpTexture );
private:
static std::list< LPBATCHMAP > s_InstanceMap;
LPBATCHMAP m_BatchMap;
};
Since the BATCHMAP and ClassB are created dynamically, the CollectGarbage() method will delete any 0 referenced instaces at an appropriate time ( creating and deleteing are time consuming ). Everything works good and well until the DeleteAll() method is called ( which erases everything regardless of reference counts ) which is usually on program termination but may be called at any other time.
As you can see, classA holds a pointer to it's instance of classB ( again for timing reasons ). Once DeleteAll() is called this member pointer will be dangling. I can't think of a suitable way to overcome this.
|
|
|
|
|
And what is the problem exactly ? Because classA now holds a pointer that points to invalid memory ?
You said that DeleteAll is called at program termination, so what is the problem exactly ?
Anyway, what you could do, is to wrap your structure in a smart pointer. A smart pointer is a class that owns a pointer to a dynamically allocated object. It overload the -> and * operators so that you can use it as if you were using the nested object directly. The purpose of smart pointers is that they will destroy automatically the object as soon as nobody use it anymore. There is a reference counting in the smart counter and this ref counting is shared across all instances of the 'same' smart pointer (by same I mean the smart pointers that hold the same pointer). You can copy the smart pointer for example (this will increment the ref counting)...
There is a smart pointer class in the boost library. Take a look here[^] for a nice article about it.
|
|
|
|
|
Cedric Moonen wrote: You said that DeleteAll is called at program termination, so what is the problem exactly ?
I also mentioned that it could be called at any other time. classB manipulates the GPU memory directly, this memory could be lost at anytime upon which my program recieves a notification that all classB instances should be re-created.
I have just been reading an article about smart pointers. I think they are just what I'm looking for.
Thanks.
|
|
|
|
|
he he he nice article.. also auto_ptr do the same
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hello,
I have derived a class from CDBVariant
class Variant : public CDBVariant
{
CString m_strVal;
};
Now I have
vector<variant>myDataTable;
But if I try to add a member by writing
myDataTable.push_back(v); where v is of type Variant
then I get an error "Unhandled exception,Access violation"
do I have to write something about allocators when declaring vector<variant>.
I am not aware of allocators so do I need to learn them and use properly.
Thanks
Prithaa
|
|
|
|
|
Can you sow complete relevent code using pre tags ?
|
|
|
|
|
Hello,
I will not be able to write the code but these are few lines more in the code
class Variant : public CDBVariant
{
operator () <
operator () >
CString m_strVal;
};
Now I have
vector<Variant>myDataTable;
But if I try to add a member by writing
myDataTable.push_back(v); where v is of type Variant
then I get an error "Unhandled exception,Access violation"
Thanks for replying
Prithaa
|
|
|
|
|
First, use your debugger to locate from where the error comes from. Then, if you are still stuck, post some relevant code and use the pre tag to format your code, otherwise we can't read anything (the pre tag is just above the emoticons).
|
|
|
|
|
I have created an application in VC++ in which i use a linked list to store and manipulate data.Now i want to store the data present in the data structure in some ODBC so that i dont lose it when my application closes.How can i go about doing it?
Susanta.
|
|
|
|
|
|
thanks MaHeSG.
I was lookin for something that could help me load tha data present in a link list to the Database and also reterive it back from the database.
Susanta.
|
|
|
|
|
Dear all,
I have some problem while using combobox in my application. The thing is , I want to reload some values to the combo at runtime..
So I choose this way..
myctrlcmb.Clear()
myctrlCmb.ResetContent();
ReloadNewValuesToCombo(&myctrlCmb); // a user defined fun.
------------------------------------------------------------
But after reloading values , the selection in the combobox is not changed. It always shows the selection which was done before reloading the combo..
I used this combo box in a property page where two other edit boxes are also there. So I want also display some values in those edit fields based on the selection in the combo. For that I have used the "UpdateData(false)" function.
my code...(when a selection is made at the combo)--:
OnCbnSelchangeComboAuthname()
{
int iIndex= 0;
int i=0;
CString strAuthName;
ClearAllValues();
iIndex = myctrlcmb.GetCurSel();
myctrlcmb.GetLBText(iIndex,strAuthName);
dlgHandler.setAllFields(strAuthName,m_valauthdesc,m_ctrlrightlist);
m_strNewAuthName = strAuthName;
UpdateData(false); //I assume the problem creator...
}
The combo selection is completely alright when I was not using the "UpdateDate(false)" funtion..But then how can I display my values in those edit fields...
Pls help me to sove this....
Regards,
vinsankar
|
|
|
|
|
Instead of associating the Cstring variable with the Edit Box.. associate The Edit box.. and call function SetWindowText from that function to update value in edit box!..
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Why is the URL at your signature (the link provided with your name) misleading? There is no such website called www.thatsalok.com!
The greater the difficulty, the greater the glory.
- Marcus Tullius Cicero
|
|
|
|
|
Sure there is!
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Mark Salsbery wrote: Sure there is!
That is routing to some domain sponsor and there is no such website. See this[^]
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
That's strange I go to "Welcome to thatsalok.com"
Beats me!
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
You must be landing up at a domain sponsor too. Can you upload a pic?
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
It has a picture of clouds and flowers and a list of links - Chat rooms, Thats, Homes for Sale,
etc.
Is that the one you see? I just assumed that was his domain
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Mark Salsbery wrote: Is that the one you see?
No. I Screen-captured and uploaded what I saw.
Mark Salsbery wrote: I just assumed that was his domain
No, Sure it isn't. You may land up on domain sponsor advertisements, which sometimes vary depending on your service provider, geographical location, etc.
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
I clicked your link yesterday and didn't even notice it was a snapshot. Ooops.
Here's[^] a snapshot of what I see.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Mark Salsbery wrote: Here's[^] a snapshot of what I see.
That is not his home page. That is some domain sponsor and most of the time, such websites would lead to some nasty links. These domain sponsors could just about randomly appear when you mistype URLs, and type URLs which does not actually exist. (I am unsure here)
In addition to that, there is another possibility. See this link[^]
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
Vinod A Sankaranarayanan wrote: The combo selection is completely alright when I was not using the "UpdateDate(false)" funtion..But then how can I display my values in those edit fields...
try http://www.codeproject.com/cpp/avoidupdatedata.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Dear Alok,
Thanks for giving me a valuable suggestion...
I have solved my problem by using the "SetWindowText" functionality of the CEdit ...
ctrlEdit.SetWindowText("khfkhd");
thus I avoid "UpdateData()"....
also Thanks to Mr.NewComer ..for the great article...
Regards
vinsankar
|
|
|
|