|
If I understand your question and the related code :
yes.
|
|
|
|
|
You did not use the <pre>-tags for your code, so the < and > and anything in between are lost. So I can not see what type of list you created.
But in general, you need to delete every single object if you are having a list of pointers to objects you new ed. In that case, you could use smart-pointers (like boost::shared_ptr[^] [but not std::auto_ptr]) in your list.
Have you considered using a string class?
-- modified at 9:14 Thursday 23rd August, 2007
clickety
-- modified at 9:19 Thursday 23rd August, 2007
I did not read his code hard enough.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
jhwurmbach wrote: smart-pointers (like boost::shared_ptr[^] [but not std::auto_ptr])
why not standard ones ?
|
|
|
|
|
Reference counting vs. ownership differences may be significant depending on how the objects are used?
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Because when you copy an auto_ptr , ownership of the object pointed to by the auto_ptr is transfered to the copying auto_ptr , and the copied auto_ptr is set to NULL.
So, simply copying an auto_ptr changes its value!
And internally, STL-container copy their content whenever needed. They require their content to be copy-constructible.
Also, the standard forbids containers of std::auto_ptr , but real-world STL-Implementation compile them nonetheless.
From "Scott Myers, Effective STL, Item 8"
For this reason, boost did invent smart pointers exhibiting a more intuitive behavior.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
|
Thanks, these are char*
They were gone because of HTML formatting!
Ang good beginner tutorial on Smart Pointer?
|
|
|
|
|
devvvy wrote: Ang good beginner tutorial on Smart Pointer?
Hmm - no, sorry. Google gives a lot of hints with tips, but no concise tutorial.
You construct them like this
boost::shared_ptr<Object> Obj( new Object);
and now use Obj like any pointer to an object: use as function parameters, return from function etc.
At the time when the last copy of the smart_ptr goes out of scope, the contained object is delete d.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
devvvy wrote: delete pRecords; <--- QUESTION: Do I need to delete individual list element?
Yes, since SomeFunc() allocated memory for it.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am trying to learn how to play with STL -- allocating/deallocating for list and individual list elements!
Note, all list contains char* list element:
list[char*] --- HTML formatting removed the proper tags...
<br />
#include [list]<br />
<br />
using namespace std;<br />
<br />
list<char*> * AllocateRecords() <br />
{<br />
list<char*> * pRecords = new list<char*>;<br />
char * pszData =NULL;<br />
<br />
for(int i=0; i<10000; i++)<br />
{<br />
pszData = new char[100];<br />
for(int j=0; j<100; j++)<br />
{<br />
pszData[j]='\0';
}<br />
sprintf(pszData, "Data#%d", i);<br />
pRecords->push_back(pszData);<br />
}<br />
<br />
return pRecords;<br />
}<br />
<br />
void ProcessRecords(list<char*> * pRecords)<br />
{<br />
<br />
return;<br />
}<br />
<br />
void DeallocateList(list<char*> * pList)<br />
{<br />
list<char*>::iterator oIter;<br />
char *pszData = NULL;<br />
<br />
if(pList==NULL)<br />
return;<br />
<br />
oIter = pList->end();<br />
oIter--;<br />
<br />
while(oIter != pList->begin())<br />
{ <br />
pszData = *oIter;
<br />
<br />
pList->pop_back(); <br />
<br />
<br />
pszData = NULL;<br />
<br />
<br />
<br />
oIter --;
}<br />
<br />
<br />
pList->clear();<br />
<br />
<br />
pList = NULL;<br />
<br />
return;<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
int nRepeat = 0;<br />
<br />
printf("begins!\n");<br />
<br />
list<char*> * pRecords = NULL; <br />
while(nRepeat<10000)<br />
{<br />
pRecords = AllocateRecords();<br />
ProcessRecords(pRecords);<br />
DeallocateList(pRecords); <br />
}<br />
<br />
return 0;<br />
}<br />
Many thanks!
-- modified at 23:03 Thursday 23rd August, 2007
|
|
|
|
|
devvvy wrote: Note, all list contains char* list element:
list[char*] --- HTML formatting removed the proper tags...
#include <list>
using namespace std;
typedef list<char*> charlist;
charlist *AllocateRecords()
{
charlist *pRecords = new charlist;
char *pszData = NULL;
for (int i = 0; i < 10000; i++)
{
pszData = new char[100];
for (int j = 0; j < 100; j++)
pszData[j] = '\0';
sprintf(pszData, "Data#%d", i);
pRecords->push_back(pszData);
}
return pRecords;
}
void ProcessRecords(charlist *pRecords)
{
charlist::iterator oIter;
for (oIter = pRecords->begin(); oIter != pRecords->end(); oIter++)
cout << *oIter << endl;
}
void DeallocateList(charlist *pList)
{
charlist::iterator oIter;
char *pszData = NULL;
if (NULL == pList)
return;
for (oIter = pList->begin(); oIter != pList->end(); oIter++)
{
pszData = *oIter;
delete [] pszData;
pszData = NULL;
}
pList->clear();
delete pList;
pList = NULL;
}
void main( void )
{
int nRepeat = 0;
charlist *pRecords = NULL;
cout << "begins!" << endl;
while (nRepeat < 10000)
{
pRecords = AllocateRecords();
ProcessRecords(pRecords);
DeallocateList(pRecords);
nRepeat++;
}
cout << "ends!" << endl;
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
I am developing XPCOM component for C++. I am following steps from following link
http://www.iosart.com/firefox/xpcom
Could you plz tell me that what is the difference between YOUR_INTERFACE_GUID and YOUR_COMPONENT_GUID? and from where can i generate those GUIDs..??
They say that use guidgen utility...but I am confused between above 2 ids..I don't know they are different or not..
Thanks a lot.
|
|
|
|
|
veer_in wrote: I don't know they are different or not..
Yes, they are different. One is for the interface, the other is for the component.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Ok. Thanks..
But could you please tell me how can i generate both? One from Visual studio \common\tools\bin.
And other from???
Plus which is what id? I am really not aware pf that..
Thanks.
|
|
|
|
|
veer_in wrote: But could you please tell me how can i generate both?
As suggested, use Guidgen.
If these concepts are foreign to you, perhaps a simpler project is in order.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Alright.
But using this project, Do i have to use the GUID i generate or can i use the same they have given?
|
|
|
|
|
veer_in wrote: Do i have to use the GUID i generate or can i use the same they have given?
Assuming you know what a GUID is, specifically the U part, this question makes no sense.
Run the utility and see what it produces.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hey don't make me confused..k I am new bee to XPCOM and just trying to register a component.
regarding utility....Yeah ofcourse it produces GUID only..!! But I don't know how to use it...( I am not talking abt how to copy ..k!!)
So if u wish you can suggest me..(Of course I need help)!!
Thanks a lot..
-- modified at 10:20 Thursday 23rd August, 2007
|
|
|
|
|
veer_in wrote: So if u wish you can suggest me..(
I suggest you use it as-is. That's the simplest approach for now.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Slowly running out of words?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
veer_in wrote: I am following steps from following link [...]
And which part of
Create a GUID for your main interface.
* On Windows you can use the guidgen utility. you were unable to comprehend?
Use guidgen (among the tools in your VisualStudio Tools Menu, or on your HD among the other VisualStudio tools).
This is - as trivially follows from the phrase "...for your interface..." - YOUR_INTERFACE_GUID.
The same way, you create a guid for your application and use it whereever YOUR_COMPONENT_GUID is asked for.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Yeah, I cud use that VisualStudio Tools Menu Guid utility..But that is for Component of interface?
If it is for interface then how can i generate for Component? Is there any other utility?
Thanks.
|
|
|
|
|
Have you even tried it? Everytime you call the tool, you get a unique guid. A different one.
So when asked by the tutorial you are following, you create a guid for the interface.
Later, when asked to create one for the app, you create another one.
Its really that simple.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
As others have said, use guidgen. But sometimes your program may need to create them on the fly:
CString GUIDgen()
{
GUID guid;
CoCreateGuid(&guid);
BYTE * str;
UuidToString((UUID*)&guid, &str);
CString unique((LPTSTR)str);
RpcStringFree(&str);
unique.Replace(_T("-"), _T("_"));
return unique;
}
|
|
|
|
|