|
I think you can do this in CChildView::OnCreate handler for WM_CREATE notification.
|
|
|
|
|
Hello,
how to sort an vector! is there any codesnippet or example for me? i try but my solution dont works!
This is what i try before:
<br />
typedef vector<CVector>VectorGlobal;<br />
VectorGlobal vec;<br />
<br />
while(int_value < 10)<br />
{<br />
vec.push_back(CVector(int_value, cstring_value, cstring_value));<br />
}<br />
<br />
VectorGlobal::iterator iter;<br />
<br />
for(iter = vec.begin(); iter != vec.end(); iter++)<br />
{<br />
TRACE(L"CSindex: %s, Url: %s\n", iter->csIndex, iter->csUrl);<br />
}<br />
sort(vec.begin(), &vec[vec.size()]);<br />
<br />
for(iter = vec.begin(); iter != vec.end(); iter++)<br />
{<br />
TRACE(L"CSindex: %s, Url: %s\n", iter->csIndex, iter->csUrl);<br />
}<br />
after i call the sort function the datas stay unsortet, where is the error, how to call the sortfunction für an vector?
regards
break;
-- modified at 10:24 Wednesday 21st June, 2006
|
|
|
|
|
|
break; wrote: sort(vec.begin(), &vec[vec.size()]);
?
try: sort(vec.begin(), vec.end());
but, more importantly, since you have a vector of CVector, what does your CVector comparison function look like ?
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Hi,
thaks for answers, the CVector is maybe a wrong name, this is very simple class:
<br />
class CVector<br />
{<br />
public:<br />
CString csName;<br />
CString csLastName;<br />
UINT iIndex;<br />
}<br />
bool operator==(const CVector& x, const CVector& y)<br />
{<br />
return (x.csUrl == y.csUrl) && (x.iIndex == y.iIndex);<br />
}<br />
<br />
bool operator<(const CVector& x, const CVector& y)<br />
{<br />
return x.iIndex < y.iIndex;<br />
}<br />
and the compare functions are global, this sample is from the MSDN!!
break;
-- modified at 10:31 Wednesday 21st June, 2006
|
|
|
|
|
if i run your code (with minor adjustments to make it compile - and fill with random data), it works fine - they are sorted by index:
class CVector
{
public:
CString csIndex;
CString csUrl;
UINT iIndex;
CVector(int i, char *a, char *b)
{
iIndex = i;
csIndex = a;
csUrl = b;
}
};
bool operator==(const CVector& x, const CVector& y)
{
return (x.csUrl == y.csUrl) && (x.iIndex == y.iIndex);
}
bool operator<(const CVector& x, const CVector& y)
{
return x.iIndex < y.iIndex;
}
.... main
typedef vector < CVector > VectorGlobal;
VectorGlobal vec;
int int_value = 0;
while(int_value < 10)
{
char a[2];
a[0] = 'a' + (rand() % 26);
char b[2];
b[0]= 'A' + (rand() % 26);
a[1]=b[1]=0;
vec.push_back(CVector(rand() % 40, a, b));
int_value++;
}
VectorGlobal::iterator iter;
for(iter = vec.begin(); iter != vec.end(); iter++)
{
TRACE("CSindex: %s, Url: %s Idx: %d\n", iter->csIndex, iter->csUrl, iter->iIndex);
}
sort(vec.begin(), vec.end());
for(iter = vec.begin(); iter != vec.end(); iter++)
{
TRACE("CSindex: %s, Url: %s Idx: %d\n", iter->csIndex, iter->csUrl, iter->iIndex);
}
output:
CSindex: p, Url: H Idx: 14
CSindex: g, Url: H Idx: 4
CSindex: m, Url: E Idx: 2
CSindex: y, Url: L Idx: 25
CSindex: l, Url: F Idx: 1
CSindex: x, Url: F Idx: 22
CSindex: r, Url: C Idx: 31
CSindex: s, Url: C Idx: 33
CSindex: g, Url: G Idx: 21
CSindex: w, Url: K Idx: 15
CSindex: l, Url: F Idx: 1
CSindex: m, Url: E Idx: 2
CSindex: g, Url: H Idx: 4
CSindex: p, Url: H Idx: 14
CSindex: w, Url: K Idx: 15
CSindex: g, Url: G Idx: 21
CSindex: x, Url: F Idx: 22
CSindex: y, Url: L Idx: 25
CSindex: r, Url: C Idx: 31
CSindex: s, Url: C Idx: 33
Cleek | Image Toolkits | Thumbnail maker
-- modified at 10:48 Wednesday 21st June, 2006
|
|
|
|
|
Hi Chris,
thanx for answer, i try the same, but take no efect!
break;
|
|
|
|
|
Try this:
class CVector<br />
{<br />
bool operator< (const CVector& that)<br />
{<br />
return this.data < that.data;<br />
}<br />
};<br />
<br />
typedef vector<CVector> VectorGlobal;<br />
VectorGlobal vec;<br />
<br />
while(int_value < 10)<br />
{<br />
vec.push_back(CVector(int_value, cstring_value, cstring_value));<br />
}<br />
<br />
void print(const CVector& v)<br />
{<br />
TRACE(L"CSindex: %s, Url: %s\n", v.csIndex, v.csUrl);<br />
}<br />
<br />
for_each(vec.begin(), vec.end(), print);<br />
sort(vec.begin(), vec.end());<br />
for_each(vec.begin(), vec.end(), print);
As a side note, use STL algorithms instead of custom loops whenever possible (which is almost always).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hello,
this is my class CVector, i change the operator funkctions to:
<br />
class CVector
{<br />
public:<br />
CString csName;<br />
CString csIndex;<br />
UINT iIndex;<br />
public:<br />
<br />
CVector()<br />
{<br />
<br />
csIndex = L"";<br />
csName = L""; <br />
iIndex = 0;<br />
}<br />
CVector(UINT index,CString csindex, CString csname,...)<br />
{<br />
iIndex = index;<br />
csIndex = csindex;<br />
csName= csname;<br />
} <br />
<br />
<br />
bool operator==(const CVector& y)<br />
{<br />
<br />
return (csUrl == y.csUrl) && (iIndex == y.iIndex);<br />
}<br />
<br />
<br />
bool operator<(const CVector& y)<br />
{<br />
return iIndex < y.iIndex;<br />
}<br />
<br />
};<br />
i try now to finish with your sample!
regards
break;
-- modified at 10:40 Wednesday 21st June, 2006
|
|
|
|
|
|
If it's not a vector of a built-in type, should you use this format of sort():
std::sort(vec.begin(), vec.end(), CompareFunction(vec)); where CompareFunction() is defined by you based on your vector type.
Check out this CP article.
Best,
Jun
|
|
|
|
|
Hello comunity,
thanx a lot for help, i solve the problem, it works!
regards
break;
|
|
|
|
|
I am in need for reading huge files (*.txt, *.dbf, *.csv) of around 4+ gb and displaying the contents of
the file page by page. Application also requires to display scrolling data. Functions like ShowLongestString() which would search entire file and display the string.
The current method of reading the files is very slow(using CFile). I have two options to improve the performance.
1) Using CMemFile.
2) Reading the file in chunks at a time and displaying the same. But I wonder how would ShowLongestString() functions perform. Also if the file is in a network it might make the overall system slower for every chunk of data read.
I am confused into wich way to go. Or of there is any better way. Any help with this will be very much appreciated.
Thanks and Regards,
Arti Gujare
-- modified at 10:01 Wednesday 21st June, 2006
|
|
|
|
|
Also please note that I read the whole file into a memory buffer and so its a slow one time read operation.
I have not used CMemfile before. So I am not sure whether CMemfile will satisfy all the app requirements.
|
|
|
|
|
ArtiGujare wrote: Also please note that I read the whole file into a memory buffer...
How are you reading a 4GB file into memory?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The File size read is less right now. around 20kb. But application might have to read huge files around 4GB.
|
|
|
|
|
Reading a 20KB file into memory is fine. In fact, reading several MB into memory will not cause a noticeable impact on performance.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I'm hoping you meant 4 MB and not 4 GB. Loading a 4 GB file into memory would be extremely painful and slow your system down to a crawl (if the system even lets you allocate the buffer to begin with). Not to mention that displaying such a file would be insane since no one in their right mind would be able to read 4 GB of data.
That said, if you did mean 4 MB, just load it into a memory buffer. The load operation will be slow, but all operations after that will be much faster. If you are doing this for a lot of files, I would try to come up with some sort of bufferring scheme to minimize the amount of memory needed to hold all the files data (e.g. cache the most recent data and serialize the rest to a temporary file until they become active again).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Use file mapping (MapViewOfFile() etc...) to only map part of the file into memory at a time.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I would suggest memory mapping sections of the file, like 5MB at a time, if you are going to be paging through the file. As you approach the end of a 5MB segment, look for an end of page marker and then reset the map starting at that marker. You can do the same thing paging backwards, too.
Remember that if you want to map the entire file in memory, you need a contigious address range available, which starts to get tricky when you get to sizes that are around 1GB+, let alone much larger.
You will not be able to map files that approach 2GB in size because IIRC, by default a Win32 process only gets 2GB of user address space allocated to it, and your application has likely already used some portion of that space. To map entire files that are 2GB and above, you will likely have to research the /3GB linker switch and how to write for and work with PAE and/or AWE. Such things are generally far beyond the scope of this message board!
Peace!
-=- James 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! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hello everyone,
What does FARPROC* mean on Windows platform? I can not find detailed descriptions from MSDN.
Another question, what should I do if I am going to port source code containing such keyword to other platforms -- like Linux?
thanks in advance,
George
|
|
|
|
|
FARPROC is defined in the WINDOWS.H file as follows:
typedef int (CALLBACK* FARPROC)();
|
|
|
|
|
Thank you zouchao1112!
I think it means a function pointer without any input parameters and returns int type, right?
What means CALLBACK?
regards,
George
|
|
|
|
|
|
Hi man,
It is a very good article. Actually, I know what means __cdecl, __stdcall or something similar. The problem is that, there seems not enough documents about what means FARPROC -- I can not find related information from this article.
regards,
George
|
|
|
|
|