News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

I can't concatenate binary files

Started by Sergiu FUNIERU, February 26, 2010, 10:18:19 PM

Previous topic - Next topic

clive

#15
Quote from: Sergiu Funieru on February 26, 2010, 11:59:09 PM
Because to find the length of the file I need to read the entire file first.

Not exactly, you should be able to fseek() to the end, and then use ftell(). It is not necessary to actually pull file data into memory to do this. And there are some more efficient Win32 methods to get the file size by querying the file handle into the file system.

Also as pointed out earlier you don't need the fseek() between the two fwrite()s. With my files systems hat on, I can tell you that fseek() is a very expensive call. It is useful if you are switch between reads and writes to a file stream, but it will act as a "fencing" operation and will flush all buffering to the media.

Ideally you should keep track of where the file pointer is, by tracking any fseek/fread/fwrite operations, and only use fseek() when required. Even a simple operation like :

if (ftell(f) != offset) fseek(f, offset, SEEK_SET);

can improve performance dramatically.

-Clive
It could be a random act of randomness. Those happen a lot as well.

jj2007

Quote from: clive on February 27, 2010, 12:34:33 AM
there are some more efficient Win32 methods to get the file size by querying the file handle into the file system.

see the get file size thread.

P.S.: For the lazybones:
include \masm32\MasmBasic\MasmBasic.inc

.code
start: Open "O", #1, "WinComplete.inc"
Print #1, FileRead$("\Masm32\include\Windows.inc"), FileRead$("\Masm32\include\WinExtra.inc")
Close
Exit
end start

Pure Massemblertm :wink

hutch--

The task itself is trivial, if the files are not massive (IE: gigabytes) and each file will fit into available memory you create a new file, open the first file and read it into memory then write it to the new file, without closing the new file, open the second and read it into memory and write it to the new file, close the new file handle and wait until the lazy write is finished unless you flush the file and its all done !
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

aker

ReadFile+OpenFileMapping+SetFilePointer+WriteFile
伟大的恐怖主义革命家拉登,因遭袭医治无效,于2011年5月1日在巴基斯坦逝世,享年54岁