|
Are you pre-allocating space for the array or re-allocating each time something new is added to it?
Are you reading in the file a line at a time or reading in each character individually and performing a "find" after each character is read?
************************************
What does the process your using look like? It would greatly assist in finding any obvious inefficiencies.
|
|
|
|
|
Im reading in a line at a time...finding tab's, storing the locations of the tab's in an array then putting the array in a function where it pulls the necessary colums and does statistical analysis on it.
For example:
Line 1:
string line={1 1 1 1000 5}
loc=line.find('\t'...);//put this in array[0] and next tab in array[1]
array[]={location of tabs};
temp.assign(line,array[3],array[4]-array[3]);
at the moment temp=1000
now do something with that
and repeate using line 2 with getline(file,line)
|
|
|
|
|
Code would have been easier to digest but regardless, nothing jumps out that should cause an unreasonable delay. How much time are we talking here?
|
|
|
|
|
Hello, here is the function. The main function gets a line at a time from the file puts the line in the function and the function returns the array of tab positions via array reference. Hope this makes it easier. Thanks
<br />
int get_cols(int (&pos)[50], string line){<br />
<br />
<br />
unsigned int i,loc=0,x=0;<br />
for(i=0;;i++){<br />
<br />
loc=line.find('\t',x);<br />
<br />
if( loc != -1 ) {
pos[i+1]=loc+1;<br />
x=loc+1;<br />
}<br />
<br />
else{<br />
pos[i+1]=line.size();
break;<br />
}<br />
}<br />
<br />
<br />
x=loc=0;<br />
<br />
<br />
return 0;<br />
<br />
}<br />
|
|
|
|
|
I see nothing that would contribute to a noticeable increase in the time it takes to process a line of text. An optimizing compiler would catch and eliminate the few redundant instructions I see.
I'm more familiar with MFC's CString than basic_string or string. CString will not create a new copy of the string when passed into a function by value unless the function modifies the string. I'm not sure if basic_string or string have this ability. If not, you may save a few clock ticks by passing it in by reference but I'm guessing you won't notice or perceive any time savings but it's worth a try...
int get_cols(int (&pos)[50],const string& line){
The only unrelated things worth mentioning are...
the line x=loc=0; is not needed since they go out of scope right afterwards anyway and the function always returns the same value which raises the question whether a return value should even be defined for the function. I would return the column count so the caller could detect an error (i.e. too many columns or fewer than expected)
How long does it take to process a 90,000 line file for you? You may have issues elsewhere in the code if the time is excessive.
|
|
|
|
|
What does the code for reading the file look like?
Do you read the file from a slow media?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
hi!
can someone give me a sample code on how to pass 2 different structs to a function with lpvoid as parameter and how to convert back to the structs from lpvoid.
the structs should be received by the lpvoid... how to combine the 2 different structs together? and how to split the lpvoid back to the 2 structs?
the structs are something like
typedef struct
{ int dataStructCount;
DWORD totalSize;
} strHeader;
typedef struct
{ int num;
lptstr str;
} dataStruct;
the function to receive
func(LPVOID data)
{
// get the structs from data
}
this will be used for writing and reading data from named pipe.. the header will be used to determine the count of dataStruct send/read.
thanks for any help!
newbie
|
|
|
|
|
I have not idea why you would want to do this but:
void func(LPVOID data)
{
strHeader *pH = (strHeader*)data;
dataStruct *pS = (datasStruct*)(data + sizeof(strHeader));
}
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
A better way:
typedef struct
{
strHeader sh;
dataStruct dh;
} myData;
Void func( myData* md)
{
md->sh ….;
md->dh….;
}
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Although I don't know exactly what you are trying to accomplish, I would think you would just want to overload the function with different parameters.
For Example:
<br />
void MyFunction(strHeader tStruct)<br />
{<br />
}<br />
void MyFunction(dataStruct tStruct)<br />
{<br />
}<br />
Dustin
|
|
|
|
|
hi... thanks for the replies!
the idea in having the structs header and data is because the receiving end of the pipe have no idea how many data structs will be sent... thus the header contains the count of data structs. it will be written on the pipe together (header and data) and will be read by the other end of the pipe... the problem i have is how to code it efficiently...
i figured maybe i can just call readfile twice... read the header first and then the data.. since the header will also contain the size of the data struct sent..
for any better ideas pls do reply!
thanks again!
newbie
|
|
|
|
|
ginjikun wrote: i figured maybe i can just call readfile twice... read the header first and then the data.. since the header will also contain the size of the data struct sent..
Often, that's the only way to do it with pipes, sockets, etc. and a protocol that supports
variable length data.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi all:
First ,I declare three variables:
IXMLDOMDocumentPtr pXMLDoc;
IXMLDOMNodePtr pNode=NULL;
HRESULT hr;
hr=pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
hr=pXMLDoc->loadXML(_bstr_t(sPath+"MAPDOMAIN.xml"));
The variable of hr shows that the pXMLDoc has been loaded successfully,and pXMLDoc is not NULL.But,I use pXMLDoc ::selectSingleNode:
pNode=pXMLDoc->selectSingleNode(_bstr_t("MAPDOMAIN"));//MAPDOMAIN is RootNode
The strange thing is that the pNode is NULL ,how can that happen?
My XML file is like this:
?xml version="1.0" encoding="gb2312"?>
<!--njnu-->
<MAPDOMAIN>
<DEVELOPMENTZONEDOMAIN>
<XMIN>135400</XMIN>
<YMIN>155900</YMIN>
<XMAX>141600</XMAX>
<YMAX>161600</YMAX>
</DEVELOPMENTZONEDOMAIN>
<AINDEXINFOFIELDNAME>
<OWNID></OWNID>
<MAPLEFT></MAPLEFT>
<MAPUPPER></MAPUPPER>
<MAPRIGHT></MAPRIGHT>
<MAPLOWER></MAPLOWER>
<UPPERLEFT></UPPERLEFT>
<UPPERRIGHT></UPPERRIGHT>
<LOWERLEFT></LOWERLEFT>
<LOWERRIGHT></LOWERRIGHT>
<INSERTFLAG></INSERTFLAG>
</AINDEXINFOFIELDNAME>
</MAPDOMAIN>
-- modified at 21:23 Saturday 14th April, 2007
|
|
|
|
|
You are assuming the XML document starts at the Document Element. Your XPath should be "/MAPDOMAIN".
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Sorry,I didn't understand very well,do you think the the code
pNode=pXMLDoc->selectSingleNode(_bstr_t("MAPDOMAIN"));
shoud be replaced by
pNode=pXMLDoc->selectSingleNode(_bstr_t("/MAPDOMAIN")); ?
Thanks!
|
|
|
|
|
Yes. The "/" is the actual root and "MAPDOMAIN" is a child of the root or the Document Element in this case.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I'v tried what you said,but the value of pNode is still NULL.
|
|
|
|
|
I'v tried what you said,but the value of pNode is still NULL.
and Could you tell me the difference between Load and LoadXML?
When I use LoadXML,it's successful,but the Load is failed,why?
Thanks a lot!
|
|
|
|
|
"LoadXML" loads the XML document from a string and "Load" from a file. I wrote some code to load from a file:
#ifdef _DEBUG
#pragma comment(lib, "comsuppwd.lib")
#else
#pragma comment(lib, "comsuppw.lib")
#endif
#include <stdio.h>
#include <tchar.h>
#import <msxml6.dll>
using namespace MSXML2;
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
HRESULT hr;
IXMLDOMDocumentPtr pXMLDom;
hr = pXMLDom.CreateInstance(__uuidof(DOMDocument60));
if (FAILED(hr))
{
printf("Failed to instantiate DOMDocument80 class\n");
return -1;
}
pXMLDom->async = VARIANT_FALSE;
if(pXMLDom->load(L"MapDomain.xml") != VARIANT_TRUE)
{
printf("Failed load xml data from file.\n%s\n",
(LPCSTR)pXMLDom->parseError->Getreason());
return -1;
}
IXMLDOMNodePtr pNode = pXMLDom->selectSingleNode(L"/MAPDOMAIN");
if (pNode == NULL)
{
printf("Invalid node fetched.\n%s\n",
(LPCSTR)pXMLDom->parseError->Getreason());
}
else
{
printf("Result from selectSingleNode:\nNode - <%s>:\n",
(LPCSTR)pNode->nodeName);
}
pNode.Release();
pXMLDom.Release();
CoUninitialize();
return 0;
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-- modified at 23:52 Saturday 14th April, 2007
|
|
|
|
|
Thank you very much!The problem is solved!!!
Thanks!
|
|
|
|
|
Also, make sure the pathname to your xml document is correct. An incorrect pathname could cause it to fail.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
In a Win32 app I am able to set global keyboard hooks, but not a local hook. I've coded the call as required for a local hook but it complains that GetCurrentThreadID can't be found. But I see that winbase.h (invoked by windows.h) contains the following declaration of GetCurrentThreadId:
WINBASEAPI
DWORD
WINAPI
GetCurrentThreadId(
VOID
);
The following call setting a global hook works fine:
HHOOK hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, HookProc,
hinstExe,
0);
The identical pgm with the following call setting a LOCAL hook fails:
HHOOK hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, HookProc,
NULL,
GetCurrentThreadID());
The error it gives is:
error C3861: 'GetCurrentThreadID': identifier not found, even with argument-dependent lookup
I've seen docs saying that GetCurrentThreadID is deprecated, but there's no alternative given. Surely there must be some way a thread can find out its own thread id, but I haven't been able to find out how. I'm using VS 2003 tools.
Any ideas anyone?
Many thanks in advance!
glyfyx
|
|
|
|
|
Try changing ID to Id.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
glyfyx wrote: I've seen docs saying that GetCurrentThreadID is deprecated
As of Platform SDK R2, it's not marked deprecated.
And, it's GetCurrentThreadId
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks Mark - very much!!
That's what I get for spending the last several years doing VB!
I won't do that again - even once is too often!
Thanks again..
glyfyx
|
|
|
|