Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » BlockStream::_Get does not buffer data (current svn version)
BlockStream::_Get does not buffer data (current svn version) [message #15442] Wed, 23 April 2008 22:23 Go to next message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
In the function

dword BlockStream::_Get(void *data, dword size)

the call to SyncPage resets the read buffer, so the normal Get() functions of Stream are not benefit from buffering.
	if(pg0 == pg1) {
		SyncPage(); // <--- here
		memcpy(data, buffer + pos0 - pos, size);
		ptr = buffer + pos1 - pos;
	}

I have commented out SyncPage() and this seems to fix it but I do not completely understand the code, so this may have introduce new bugs Rolling Eyes

App to reproduce (run it and see how often BlockStream::_Get() is called)

file: console.cpp
CONSOLE_APP_MAIN
{
	Cout() << "Hello wonderful U++ world\n";
	FileIn f;
	f.Open("console.cpp");
	for (;;) {
		byte b;
		if (f.Get(&b, 1) != 1) break;
		Cout() << b;
	}

}
//add many comment lines to get big filesize
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

Re: BlockStream::_Get does not buffer data (current svn version) [message #15443 is a reply to message #15442] Wed, 23 April 2008 22:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
hans wrote on Wed, 23 April 2008 16:23

In the function

dword BlockStream::_Get(void *data, dword size)

the call to SyncPage resets the read buffer, so the normal Get() functions of Stream are not benefit from buffering.




Thanks, correct.

Probably the correct fix is to call Term_():

	if(pg0 == pg1) {
		SyncPage();
		memcpy(data, buffer + pos0 - pos, size);
		ptr = buffer + pos1 - pos;
		_Term();
	}


(Calling Term_ should be OK at any time..).

Mirek
Re: BlockStream::_Get does not buffer data (current svn version) [message #15457 is a reply to message #15443] Thu, 24 April 2008 21:27 Go to previous messageGo to next message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
Thanks for the reply and confirmation.

I don't understand why calling _Term() is better though, but your suggest will fix it anyway. Very Happy
Re: BlockStream::_Get does not buffer data (current svn version) [message #15459 is a reply to message #15457] Thu, 24 April 2008 22:58 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
It is better because it fixes the problem and by definition does not do anything bad to BlockStream internal state (as long as it is implemented right Smile In other words, you can call _Term() at any time without any bad effects...

Mirek
Previous Topic: GetHWND() always returns NULL?
Next Topic: Convenient work with options/properties
Goto Forum:
  


Current Time: Sat Apr 27 12:08:40 CEST 2024

Total time taken to generate the page: 0.03976 seconds