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 » BUG? or Not BUG? LoadFile(filename) and then getting wrong data
Re: BUG? or Not BUG? LoadFile(filename) and then getting wrong data [message #33452 is a reply to message #33445] Tue, 09 August 2011 00:42 Go to previous messageGo to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
silverx wrote on Mon, 08 August 2011 09:48


Then I have a program ReadFileByte, which uses the reading it one byte at a time from the input file. Which when I try and process the large file it takes for ever, and gives me program not responding. Another issue I need to find out what to do about it.


Another interesting way is to use FileMapping to get blocks of data to process it:
#include <Core/Core.h>

using namespace Upp;

inline String PrintUsage() {
	StringBuffer sb;
	sb << "Prints hex view of selected file\n\n\
Syntax:\n"
<< GetExeTitle() << " [file]\n\n\
Options:\n\
file\t\t Path to selected file\n";
	return sb;
}

CONSOLE_APP_MAIN
{
	const Vector<String>& cl = CommandLine();

	if (cl.GetCount() == 0)
	{
		SetExitCode(0);
		Cout() << PrintUsage();
		return;
	}

	String filePath(NormalizePath(cl[0]));

	if (!FileExists(filePath))
	{
		SetExitCode(1);
		Cerr() << Format("File \"%s\" doesn't exists\n", filePath);
		return;
	}

	FileMapping fm;

	if (!fm.Open(filePath))
	{
		SetExitCode(1);
		Cerr() << Format("Can't read \"%s\" file\n", filePath);
		return;
	}

	const int wrapCount = 16,
		blockSize = wrapCount * 4096;

	int64 count = fm.GetFileSize(),
		offset = 0;

	while (count > 0)
	{
		const int lenght = min<int64>(count, blockSize);
		const String& data = fm.GetData(offset, lenght);
		count -= lenght; offset += lenght;

		for (int i = 0; i < data.GetCount(); ++i)
		{
			const String& hex = Format64Hex(byte(data[i]));
			Cout() << Format(" %2s", hex);

			if ((i + 1) % wrapCount == 0)
				Cout() << '\n';
		}
	}
}

mirek wrote on Mon, 08 August 2011 13:24


However, fix is trivial


Thanks for fix, Mirek.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Polymorphic Array doubt
Next Topic: Need help about the codepage!
Goto Forum:
  


Current Time: Fri Jul 04 23:49:50 CEST 2025

Total time taken to generate the page: 0.05488 seconds