From: Kerem G�mr�kc� on
Hi,

i have a application that reads a unknown bunch of
files to a block of memory, handles them and finally
frees the memory. For now, i work with VirtualAlloc,
but i get after processing ~250 Files a GetLastError=8
for any memory request, even i know that memory has
been released with VirtualFree=TRUE. Why is that
the case? The System has 1GB of real physical memory.
Sure i know the limitations of user memory space and
process space. VirtualAlloc will always be called with
MEM_COMMIT and PAGE_READWRITE in my code.
I have to read the complete file, not a piece of it, so
some files are 205 byte others about 20MB. So what
and how can i asure, that my application frees the
allocated memory after ist usage and what are the
differences on processing impact if i use these functions,
better to say: what are the differences between VirtualAlloc,
GlobalAlloc and HeapAlloc? The Application is a single
threaded app and expects a folder path as input, then it
processes the files:

FOR EACH FILE IN FOLDER
IsFileReadable
ReadFileSize
VirtualAlloc
ReadFileContent
DoAnalyzeFileContent
WriteToOwnAppFile
FlushBuffers
VirtualFree
NEXT FILE
ExitApplication

How can i prevent to run into a GetLastError()=8
Subsequent Memory Request fail after a GetLastError=8


Regards

K.

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."


From: Kerem G�mr�kc� on
Hi,

i had a look at its resource uttilization/usage with process
explorer and it grows exponentially expecially its "Virtual Size"
for Virtual Memory, sure for VirtualAlloc and its CPU Usage.
At a certail level it slows down the complete system and os starts
to work with the pagefile until i kill or stop the process,...

Something is wrong here, I think i should not use VirtualAlloc
or find a way to 100% give back the allocated memory and
then reallocate new memory. How can i force my application
to use real physical memory instead virtual? Dow, this belongs
to the OS and its internals, i know,...

I found this:
[Comparing Memory Allocation Methods]
http://msdn2.microsoft.com/en-us/library/aa366533.aspx

which makey my decision go HeapAlloc, because of the page granularity,...


Regards

K.

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
"Kerem G�mr�kc�" <kareem114(a)hotmail.com> schrieb im Newsbeitrag
news:ObQOrcLgIHA.484(a)TK2MSFTNGP06.phx.gbl...
> Hi,
>
> i have a application that reads a unknown bunch of
> files to a block of memory, handles them and finally
> frees the memory. For now, i work with VirtualAlloc,
> but i get after processing ~250 Files a GetLastError=8
> for any memory request, even i know that memory has
> been released with VirtualFree=TRUE. Why is that
> the case? The System has 1GB of real physical memory.
> Sure i know the limitations of user memory space and
> process space. VirtualAlloc will always be called with
> MEM_COMMIT and PAGE_READWRITE in my code.
> I have to read the complete file, not a piece of it, so
> some files are 205 byte others about 20MB. So what
> and how can i asure, that my application frees the
> allocated memory after ist usage and what are the
> differences on processing impact if i use these functions,
> better to say: what are the differences between VirtualAlloc,
> GlobalAlloc and HeapAlloc? The Application is a single
> threaded app and expects a folder path as input, then it
> processes the files:
>
> FOR EACH FILE IN FOLDER
> IsFileReadable
> ReadFileSize
> VirtualAlloc
> ReadFileContent
> DoAnalyzeFileContent
> WriteToOwnAppFile
> FlushBuffers
> VirtualFree
> NEXT FILE
> ExitApplication
>
> How can i prevent to run into a GetLastError()=8
> Subsequent Memory Request fail after a GetLastError=8
>
>
> Regards
>
> K.
>
> --
> -----------------------
> Beste Gr�sse / Best regards / Votre bien devoue
> Kerem G�mr�kc�
> Microsoft Live Space: http://kerem-g.spaces.live.com/
> Latest Open-Source Projects: http://entwicklung.junetz.de
> -----------------------
> "This reply is provided as is, without warranty express or implied."
>


From: Alexander Grigoriev on
What arguments are you passing to VirtualFree?

"Kerem G�mr�kc�" <kareem114(a)hotmail.com> wrote in message
news:ObQOrcLgIHA.484(a)TK2MSFTNGP06.phx.gbl...
> Hi,
>
> i have a application that reads a unknown bunch of
> files to a block of memory, handles them and finally
> frees the memory. For now, i work with VirtualAlloc,
> but i get after processing ~250 Files a GetLastError=8
> for any memory request, even i know that memory has
> been released with VirtualFree=TRUE. Why is that
> the case? The System has 1GB of real physical memory.
> Sure i know the limitations of user memory space and
> process space. VirtualAlloc will always be called with
> MEM_COMMIT and PAGE_READWRITE in my code.
> I have to read the complete file, not a piece of it, so
> some files are 205 byte others about 20MB. So what
> and how can i asure, that my application frees the
> allocated memory after ist usage and what are the
> differences on processing impact if i use these functions,
> better to say: what are the differences between VirtualAlloc,
> GlobalAlloc and HeapAlloc? The Application is a single
> threaded app and expects a folder path as input, then it
> processes the files:
>
> FOR EACH FILE IN FOLDER
> IsFileReadable
> ReadFileSize
> VirtualAlloc
> ReadFileContent
> DoAnalyzeFileContent
> WriteToOwnAppFile
> FlushBuffers
> VirtualFree
> NEXT FILE
> ExitApplication
>
> How can i prevent to run into a GetLastError()=8
> Subsequent Memory Request fail after a GetLastError=8
>
>
> Regards
>
> K.
>
> --
> -----------------------
> Beste Gr�sse / Best regards / Votre bien devoue
> Kerem G�mr�kc�
> Microsoft Live Space: http://kerem-g.spaces.live.com/
> Latest Open-Source Projects: http://entwicklung.junetz.de
> -----------------------
> "This reply is provided as is, without warranty express or implied."
>


From: Alex Blekhman on
"Kerem G�mr�kc�" wrote:
> I have several vrapper functions arround the VirtualAlloc and
> VirtualFree and i was passing accidentally a MEM_DECOMMIT to a
> VirtualFree, not a MEM_RELEASE and also not a zero as second
> parameter. This was not clear because of my own flags and
> complex wrappers,....dow,...

The real question here is why do you need `VirtualAlloc' at all?
You always call it with `MEM_COMMIT' and `PAGE_READWRITE' flags
making it eventually indistinguishable form regular `operator new'
or `malloc'. Actually you're making it worse since you miss all
optimizations that CRT may enable (like Low Fragmentation Heap,
for example).

I suggest you at least to try your code with regular `new' and
`delete'. Also, if you want to avoid buffer allocations
altogether, then you can use memory mapping to read the files.

Alex


From: Alexander Grigoriev on
He might want certain alignment for non-buffered IO.

"Alex Blekhman" <tkfx.REMOVE(a)yahoo.com> wrote in message
news:u%23B7IxPgIHA.1132(a)TK2MSFTNGP06.phx.gbl...
> "Kerem G�mr�kc�" wrote:
>> I have several vrapper functions arround the VirtualAlloc and VirtualFree
>> and i was passing accidentally a MEM_DECOMMIT to a VirtualFree, not a
>> MEM_RELEASE and also not a zero as second parameter. This was not clear
>> because of my own flags and complex wrappers,....dow,...
>
> The real question here is why do you need `VirtualAlloc' at all? You
> always call it with `MEM_COMMIT' and `PAGE_READWRITE' flags making it
> eventually indistinguishable form regular `operator new' or `malloc'.
> Actually you're making it worse since you miss all optimizations that CRT
> may enable (like Low Fragmentation Heap, for example).
>
> I suggest you at least to try your code with regular `new' and `delete'.
> Also, if you want to avoid buffer allocations altogether, then you can use
> memory mapping to read the files.
>
> Alex
>