OPEN PATH+"\"+FILE AS 1
OPEN PATH+"\"+FILE+"_SW.BIN" AS 2
FIELD #1,1 'ファイルフィールド長 1BYTE
FIELD #2,1 'ファイルフィールド長 1BYTE
PRINT "START";Time$()
/*データ入力&出力====================================*/
*DATA_GET
GET #1,COUNTER,K$1 'データ GET
GET #1,COUNTER+1,K$2
PUT #2,COUNTER,K$2 'SWAPデータ PUT
PUT #2,COUNTER+1,K$1
/*SUM値演算========================================*/
SUM1 = Asc(K$1)
SUM2 = Asc(K$2)
SUM_OR = SUM_OR + (SUM1*256+SUM2)
SUM_SW = SUM_SW + (SUM2*256+SUM1)
COUNTER = COUNTER+2
IF Eof(1) = -1 THEN *END_TASK 'END OF FILE
GOTO *DATA_GET
/*終了処理 ==========================================*/
*END_TASK
CLOSE 1
CLOSE 2
Dim I As Long
Dim A$ As String
Dim A As Byte
Dim StartTime As Long
Dim EndTime As Long
Dim UsedTime As Long
Dim StartTime2 As Long
Dim EndTime2 As Long
Dim UsedTime2 As Long
Declare Function timeGetTime Lib "winmm.dll" () As DWord
A$=" "
StartTime=timeGetTime()
For I=0 To 1000000
A=Asc(A$)
Next I
EndTime=timeGetTime()
StartTime2=timeGetTime()
For I=0 To 1000000
A=A$[0]
Next I
EndTime2=timeGetTime()
UsedTime=EndTime-StartTime
UsedTime2=EndTime2-StartTime2
Open "Test.txt" For Append As #1
A$=Str$(UsedTime)
Write #1,A$
A$=Str$(UsedTime2)
Write #1,A$
Close #1
MessageBox(0,"Test was end","EndDialog",0)
End
Dim I As Long
Dim A$ As String
Dim StartTime As Long
Dim EndTime As Long
Dim UsedTime As Long
Dim StartTime2 As Long
Dim EndTime2 As Long
Dim UsedTime2 As Long
Declare Function timeGetTime Lib "winmm.dll" () As DWord
I=0
StartTime=timeGetTime()
Do
I=I+1
if I>100000000 then Exit Do
Loop
EndTime=timeGetTime()
I=0
StartTime2=timeGetTime()
*A
I=I+1
if I>100000000 then goto *B
goto *A
*B
EndTime2=timeGetTime()
UsedTime=EndTime-StartTime
UsedTime2=EndTime2-StartTime2
Open "Test3.txt" For Append As #1
A$=Str$(UsedTime)
Write #1,A$
A$=Str$(UsedTime2)
Write #1,A$
Close #1
MessageBox(0,"Test was end","EndDialog",0)
End
#N88BASIC
Dim Buffer$ As String
Dim RecordSize As Long
Dim i As Long
Dim Work$ As Byte
'
'* 入力ファイル読み込み
'
Open "TestInfile.txt" For Input As #1
RecordSize=Lof(1)
Field #1,RecordSize
Get #1,1,Buffer$
Close #1
'
'* スワップ処理(1⇔2,3⇔4・・・・)
'
For i=1 To RecordSize-1 Step 2
Work$=Buffer$[i-1]
Buffer$[i-1]=Buffer$
Buffer$=Work$
Next i
'
'* 出力ファイル(bin)書き込み
'
Open "TestOutfile.txt" For Output As #2
Field #2,RecordSize
Put #2,1,Buffer$
Close #2
End
/* データ入力&出力 ====================================*/
*DATA_GET
GET #1,COUNTER,K$1 'データ GET
GET #1,COUNTER+1,K$2
PUT #2,COUNTER,K$2 'SWAPデータ PUT << 単純に1と2を入れ替えてPUTです。
PUT #2,COUNTER+1,K$1
#strict
#prompt
Const InputFile = "c:\temp\test_input.bin"
Const OutputFile = "c:\temp\test_output.bin"
Typedef BOOL = Long
timeBeginPeriod(1)'精度を1msに設定
Dim Time As DWord
Time = timeGetTime()
If BinarySwap(InputFile, OutputFile) <> FALSE Then
Time = timeGetTime() - Time
Print Time ' 所要時間の表示
End If
timeEndPeriod(1)'timeBeginPeriodで指定した値を渡す
Function BinarySwap(pszInputFile As *Char, pszOutputFile As *Char) As BOOL
BinarySwap = FALSE
' 入力ファイルのファイルマッピングオブジェクトを作成。
Dim Input As egtra_FileMapping(pszInputFile, FALSE, OPEN_EXISTING)
If Input.GetFileHandle() = INVALID_HANDLE_VALUE Then
Print "入力ファイルが開けませんでした。"
Exit Function
End If
' 入力ファイルのサイズを取得。
Dim qwFileSize As QWord, pSize As *ULARGE_INTEGER
pSize = VarPtr(qwFileSize)
pSize->LowPart = GetFileSize(Input.GetFileHandle(), VarPtr(pSize->HighPart))
If pSize->LowPart = &hffffffff And GetLastError() <> 0 Then
Print "ファイルサイズが取得できませんでした。"
Exit Function
End If
#ifndef _WIN64
If pSize->HighPart <> 0 Then
Print "このプログラムは,Win32ではこんなに巨大なファイルに対応していません。"
Exit Function
End If
#endif
' 出力ファイルのファイルマッピングオブジェクトを作成。入力ファイルと同じ大きさに設定。
Dim Output As egtra_FileMapping(pszOutputFile, TRUE, CREATE_ALWAYS, pSize->HighPart, pSize->LowPart)
If Input.GetFileHandle() = INVALID_HANDLE_VALUE Then
Print "出力ファイルが開けませんでした。"
Exit Function
End If
' ここで実際にメモリアドレスへ割り当てている。
Dim pInput As *Byte, pOutput As *Byte
pInput = Input.MapView()
pOutput = Output.MapView()
'
'* スワップ処理(1⇔2,3⇔4・・・・)
'
Dim FileSize As ULONG_PTR
FileSize = qwFileSize As ULONG_PTR
Dim i As ULONG_PTR
For i = 0 To FileSize - 1 Step 2
pOutput = pInput[i + 1]
pOutput[i + 1] = pInput
Next
' マッピングの解除
Input.UnmapView(pInput)
Output.UnmapView(pOutput)
BinarySwap = TRUE
End Function
Declare Function timeGetTime Lib "winmm" () As DWord
Declare Function timeBeginPeriod Lib "winmm" (uPeriod As DWord) As Long
Declare Function timeEndPeriod Lib "winmm" (uPeriod As DWord) As Long
Declare Function CreateFileMapping Lib "kernel32" Alias "CreateFileMappingA" (
hFile As HANDLE,
pAttributes As *SECURITY_ATTRIBUTES,
flProtect As DWord,
dwMaximumSizeHigh As DWord,
dwMaximumSizeLow As DWord,
pName As *Char
) As HANDLE
Declare Function MapViewOfFile Lib "kernel32" (
hFileMappingObject As HANDLE,
dwDesiredAccess As DWord,
dwFileOffsetHigh As DWord,
dwFileOffsetLow As DWord,
NumberOfBytesToMap As SIZE_T
) As VoidPtr
Declare Function UnmapViewOfFile Lib "kernel32" (pBaseAddress As VoidPtr) As Long
/*
Const PAGE_READONLY = &H2
Const PAGE_READWRITE = &H4
*/
Const FILE_MAP_READ = &H4
Const FILE_MAP_WRITE = &H2
'簡易ファイルマッピングクラス
Class egtra_FileMapping
Public
Sub egtra_FileMapping(pszFileName As *Char, canWrite As Long, CreationDisposition As DWord)(FileSizeHigh As DWord, FileSizeLow As DWord)
Dim CreateFileFlag As DWord, CreateFileMappingFlag As DWord
If canWrite <> FALSE Then
CreateFileFlag = GENERIC_READ Or GENERIC_WRITE
CreateFileMappingFlag = PAGE_READWRITE
DesiredAccess = FILE_MAP_WRITE
Else
CreateFileFlag = GENERIC_READ
CreateFileMappingFlag = PAGE_READONLY
DesiredAccess = FILE_MAP_READ
End If
hFile = CreateFile(pszFileName, CreateFileFlag, 0, ByVal 0, CreationDisposition, 0, 0)
If hFile = INVALID_HANDLE_VALUE Then
Exit Sub
End If
hMap = CreateFileMapping(hFile, 0, CreateFileMappingFlag, FileSizeHigh, FileSizeLow, 0)
End Sub
Function MapView() As VoidPtr
MapView = MapViewOfFile(hMap, DesiredAccess, 0, 0, 0)
End Function
/*
Function MapView(dwFileOffsetHigh As DWord, dwFileOffsetLow As DWord, NumberOfBytesToMap As SIZE_T) As VoidPtr
MapView = MapViewOfFile(hMap, DesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, NumberOfBytesToMap)
End Function
*/
Sub UnmapView(pv As VoidPtr) ' 本当は不要だが
UnmapViewOfFile(pv)
End Sub
Function GetFileHandle() As HANDLE
GetFileHandle = hFile
End Function
Sub ~egtra_FileMapping()
CloseHandle(hMap)
CloseHandle(hFile)
End Sub
Private
hFile As HANDLE
hMap As HANDLE
DesiredAccess As DWord
End Class
#N88BASIC
'
'グローバル変数領域定義
'
Dim RecordSize As QWord ' 18,446,744,073,709,551,616バイトまで
Const BunkatuSize=1024*1024*64 ' 分割サイズを偶数で指定(K,M,64Mbyte)
'
Dim LoopCount As QWord
Dim i As QWord,j As QWord,k As QWord,q As String
Dim Buffer$ As String
Dim Work$ As Byte
'
'ファイルオープン
'
Open "TestInfile.txt" For Input As #1
Open "TestOutfile.txt" For Output As #2
'
'分割処理回数演算
'
RecordSize=Lof(1)
Field #1,BunkatuSize
LoopCount=(RecordSize\BunkatuSize)+Sgn(RecordSize Mod BunkatuSize)
Print RecordSize;"バイトのデータを";BunkatuSize;"バイトに分割して";LoopCount;"回で処理します。"
'
'スワップ処理
'
For i=1 To LoopCount
Get #1,i,Buffer$
j=1
While (j<BunkatuSize) And (k<RecordSize-1)
Work$=Buffer$[j-1]
Buffer$[j-1]=Buffer$[j]
Buffer$[j]=Work$
j=j+2
k=k+2
Wend
Field #2,Len(Buffer$)
Put #2,i,Buffer$
Print i;"回目"
Next i
'
'ファイルクローズ
'
Close #1
Close #2
'
'終了
'
Input "終了しました。(Hit Enter Key)";q
End