Re: MapViewOfFile trouble
Quote:
Originally Posted by
juanpast
... When I create an array of this class and read the data with fread method it works fine but when the data is read mapping the file some files are loaded ok but after that GetLastError return 8 (from MSDN: ERROR_NOT_ENOUGH_MEMORY) .
Some idea is appreciated!!!
The idea is very simple - increase memorz!
Besides, there are some other problems in your code:
- you are using malloc in VC++ code and apply it so some class that should be treated as a serious mistake.
- you don't free the allocated memory
Re: MapViewOfFile trouble
Hi Victor and thanks for your reply.
Quote:
The idea is very simple - increase memorz!
Two methods load the same data but mapping files crashes and using fread not.
Quote:
1 you are using malloc in VC++ code and apply it so some class that should be treated as a serious mistake.
NODO and ADYACENTE are a struct not a class, is necesary use new operator?
Quote:
2 you don't free the allocated memory
Destructor of CGrafo free the memory allocated with malloc, it is not correct?
Thanks!
Re: MapViewOfFile trouble
Quote:
Originally Posted by
juanpast
Two methods load the same data but mapping files crashes and using fread not.
Perhaps, mapping requires more memory? :confused:
Quote:
Originally Posted by
juanpast
NODO and ADYACENTE are a struct not a class, is necesary use new operator?
And what is the difference between struct and class?
There is only one difference: all struct member/methods are public by default while all class member/methods are private by default.
You may use malloc/free only if your struct is a POD struct, but are you sure it is so now and will be so for ever?
Quote:
Originally Posted by
juanpast
Destructor of CGrafo free the memory allocated with malloc, it is not correct?
No, because your CGrafo::CargarGrafoBin may be called any number of times while the dtor will be called only once. :cool:
Re: MapViewOfFile trouble
Very thanks Victor.
I am doing examples with the same data and with fread works fine but mapping the file not work. It's need to take the same memory. For example:
Code:
void CargaGrafos(void) {
CGrafo vGrafos[5000];
CString szGrafo = _T("D:\\grafos\\grafo");
CString szGrafoI;
for(int i=0;i<5000;i++) {
szGrafoI.Format(_T("%s%d"), szGrafo, i);
DWORD dRes = vGrafos[i].Open(szGrafoI, 2);
//DWORD dRes = vGrafos[i].Open(szGrafoI, 1);
}
}
* Open method with second parameter = 1 read the data using
DWORD CGrafo::CargarGrafoBin(const CString &szNombre)
** Open method with second parameter = 2 read the data using
DWORD CGrafo::CargarGrafoMap(const CString &szNombre)
Running the example with 1 as parameter works fine but if the parameter is 2 it's not work.
The other things:
Quote:
Besides, there are some other problems in your code:
- you are using malloc in VC++ code and apply it so some class that should be treated as a serious mistake.
- you don't free the allocated memory
It's now clear, very thanks.
Your replies are much appreciated!