|
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;
}
|
|
|
|
|
|
Hi,
I want to display a report containing four columns and to provide printing option for that. My code is:
<br />
<br />
void CColorView::OnDraw(CDC* pDC)<br />
{<br />
<br />
CDocumentationDoc* pDoc = GetDocument();<br />
<br />
if(pDC -> IsPrinting())<br />
{<br />
<br />
pDC -> SetMapMode(MM_ISOTROPIC);<br />
<br />
pDC->SetMapMode(MM_ISOTROPIC);<br />
pDC->SetWindowExt(500, 500);<br />
pDC->SetViewportExt(4500, 6500);<br />
<br />
}<br />
<br />
pDC -> TextOut(30, 10, "COLOR");<br />
pDC -> TextOut(280, 10, "DEV-TYPE");<br />
pDC -> TextOut(600, 10, "VALUE");<br />
pDC -> TextOut(730, 10, "QUANTITY");<br />
<br />
int xinc = 40, yinc = 20, ytemp = 50;<br />
<br />
int size = FootPrintArray.GetSize();<br />
<br />
for(int i = 0; i < size; i++)<br />
{<br />
<br />
footprint = (FootPrint*) FootPrintArray.GetAt(i);<br />
<br />
BYTE red, green, blue;<br />
<br />
red = ((BYTE*)(&footprint -> color))[0];<br />
green = ((BYTE*)(&footprint -> color))[1];<br />
blue = ((BYTE*)(&footprint -> color))[2];<br />
<br />
CPen penShadow(PS_SOLID, 1, PALETTERGB(red,green,blue));<br />
CPen* ppenOld = pDC -> SelectObject(&penShadow);<br />
<br />
CBrush brCenter;<br />
brCenter.CreateSolidBrush(PALETTERGB(red,green,blue));<br />
CBrush* pbrOld = pDC -> SelectObject(&brCenter);<br />
<br />
int yval = ytemp + (i * yinc); <br />
<br />
pDC -> Rectangle(30, yval - 10, 70, yval);<br />
pDC -> TextOut(100, (yval - 10), footprint -> FtPtName);<br />
pDC -> TextOut(600, (yval - 10), footprint -> Value);<br />
pDC -> TextOut(770, (yval - 10), footprint -> Quantity);<br />
<br />
} <br />
<br />
<br />
}<br />
It is getting printed now.. i can able to take pdf from my view. But in this the row values of the columns 2 and 3 may vary to any large value at run time. How to calculate and print? Suggest me some ideas.
With Regards,
Sangeetha.
|
|
|
|
|
for getting the size of a string in CDC call CDC::GetTextExtent() method.
|
|
|
|
|
I need to calculate the text extent of a largest string at run time and position the column heading centered.
With Regards,
Sangeetha.
|
|
|
|
|
Hi
I have created 2 class derived from CPropertyPage and one class from CPropertySheet.
Font of these 2 dialogs(property pages) are Tahoma (I set it in resource editor), but when run the exe font has been changed to a another font.
I tried SetFont in my propert sheet and propert pages classes but it does NOT change the font!
Please help
|
|
|
|
|
any relevant piece of code to show what you did ?
|
|
|
|
|
I think it must work correctly without any code, just like changing font of a dialog in resource editor, for this you don't need to write any code!
But here is my try :
in my property page and property cheet constructor :
{
m_font.CreateFont(8,
0,
0,
0,
FW_NORMAL,
FALSE,
FALSE,
0,
ARABIC_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_ROMAN,
_T("Tahoma"));
}
in their OnInitDialog() :
SetFont(&m_font);
but after I compile the project and run the program, the font of propert pages are not Tahoma, I think it's MS Shell Dlg
|
|
|
|
|
Hadi Dayvary wrote: OnInitDialog() :
SetFont(&m_font);
That may be to late. The Text may have already been drawn.
Try SetFont() in Create() or PreSubclassWindows().
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
|
|
|
|
|
wrong... i once wrote the following code in a OnInitDialog() handler, and the code was working as expected :
CFont* pf = m_staticTransparent.GetFont();
LOGFONT lfLogFont = {0};
pf->GetLogFont(&lfLogFont);
lfLogFont.lfWeight = FW_BOLD;
m_fontBold.CreateFontIndirect(&lfLogFont);
m_staticTransparent.SetFont(&m_fontBold);
|
|
|
|