首页
社区
课程
招聘
[求助]关于C/C++预分配磁盘文件空间问题
发表于: 2006-12-24 11:39 8276

[求助]关于C/C++预分配磁盘文件空间问题

2006-12-24 11:39
8276
请问各位大侠怎么样才可以生成一个预先分配好大小的文件呢?
这个有没有什么标准函数

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 0
支持
分享
最新回复 (6)
雪    币: 217
活跃值: (99)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
SetFilePointer
The SetFilePointer function moves the file pointer of an open file.

DWORD SetFilePointer(
  HANDLE hFile,          // handle of file
  LONG lDistanceToMove,  // number of bytes to move file pointer
  PLONG lpDistanceToMoveHigh,
                         // pointer to high-order DWORD of
                         // distance to move
  DWORD dwMoveMethod     // how to move
);

SetEndOfFile
The SetEndOfFile function moves the end-of-file (EOF) position for the specified file to the current position of the file pointer.

BOOL SetEndOfFile(
  HANDLE hFile   // handle of file whose EOF is to be set
);
2006-12-24 16:20
0
雪    币: 14
活跃值: (2650)
能力值: ( LV12,RANK:610 )
在线值:
发帖
回帖
粉丝
3
最初由 PFC 发布
请问各位大侠怎么样才可以生成一个预先分配好大小的文件呢?
这个有没有什么标准函数


有的!

自己逆向btcomet或者flashget找吧。
2006-12-24 20:02
0
雪    币: 161
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
PFC
4
最初由 ylp1332 发布
有的!

自己逆向btcomet或者flashget找吧。

有说不==没说!
谢谢2楼的MG
2006-12-24 23:19
0
雪    币: 1852
活跃值: (504)
能力值: (RANK:1010 )
在线值:
发帖
回帖
粉丝
5
最初由 PFC 发布
请问各位大侠怎么样才可以生成一个预先分配好大小的文件呢?
这个有没有什么标准函数


推荐用内存映射机制
其在映射过程中可以指定文件大小
2006-12-25 09:16
0
雪    币: 161
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
PFC
6
最初由 北极星2003 发布
推荐用内存映射机制
其在映射过程中可以指定文件大小

我汇报下这两天想到的解决方法。
1预生成文件大小(文件大小是固定的那么可不可以先建一个文件随后写入值是全0长度到满足文件大小为止)
2因为预生成时的文件没有值也就是说将来还要在各相应地方写入值(直接COPY预先生成的文件。这样就可以达到预生成效果)
3写入要写入值时直接定位游标到文件相应位置写入主可。

呵各位看看这想法可不可以,和北极星2003的用点不同。
2006-12-25 21:53
0
雪    币: 222
活跃值: (10)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
7
这样很低效,用好SetEndOfFile就可以了,它是专门用来裁减或扩展文件体积的。

The SetEndOfFile function moves the end-of-file (EOF) position for the specified file to the current position of the file pointer.

BOOL SetEndOfFile(

    HANDLE hFile         // handle of file whose EOF is to be set
   );       

Parameters

hFile

Identifies the file to have its EOF position moved. The file handle must have been created with GENERIC_WRITE access to the file.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

This function can be used to truncate or extend a file. If the file is extended, the contents of the file between the old EOF position and the new position are not defined.
If you called CreateFileMapping to create a file-mapping object for hFile, you must first call UnmapViewOfFile to unmap all views and call CloseHandle to close the file-mapping object before you can call SetEndOfFile.
2006-12-26 02:41
0
游客
登录 | 注册 方可回帖
返回
//