ACE的文件操作

面是一个使用多种方法进行文件拷贝操作的例子:

// 1、使用操作系统的函数进行逐个字符的拷贝. read/write/lseek

int
Slow_Read_Write_Test::run_test (int iterations,
FILE *input_fp,
FILE *output_fp)
{
ACE_HANDLE ifd = fileno (input_fp);
ACE_HANDLE ofd = fileno (output_fp);

this->tm_.start ();

while (--iterations >= 0)
{
char c;

while (ACE_OS::read (ifd, &c, sizeof c) > 0)
::write (ofd, &c, sizeof c);

ACE_OS::lseek (ifd, 0, SEEK_SET);
ACE_OS::lseek (ofd, 0, SEEK_SET);
}

this->tm_.stop ();
return 0;
}

// 2. 使用标准C函数进行逐字符拷贝. getc/putc/rewind

int
Stdio_Test::run_test (int iterations,
FILE *input_fp,
FILE *output_fp)
{
this->tm_.start ();

while (--iterations >= 0)
{
int c;

while ((c = getc (input_fp)) != EOF)
putc (c, output_fp);

ACE_OS::rewind (input_fp);
ACE_OS::rewind (output_fp);
}
this->tm_.stop ();
return 0;
}

// 3. 块读取. read/write/lseek

int
Block_Read_Write_Test::run_test (int iterations,
FILE *input_fp,
FILE *output_fp)
{
int ifd = fileno (input_fp);
int ofd = fileno (output_fp);

this->tm_.start ();

while (--iterations >= 0)
{
char buf[BUFSIZ];
ssize_t n;

while ((n = ACE_OS::read (ifd,
buf,
sizeof buf)) > 0)
::write (ofd, buf, n);

ACE_OS::lseek (ifd, 0, SEEK_SET);
ACE_OS::lseek (ofd, 0, SEEK_SET);
}

this->tm_.stop ();
return 0;
}

// 4. fread/fwrite/lseek

int
Block_Fread_Fwrite_Test::run_test (int iterations,
FILE *input_fp,
FILE *output_fp)
{
this->tm_.start ();

while (--iterations >= 0)
{
char buf[BUFSIZ];
ssize_t n;

while ((n = ACE_OS::fread (buf,
1,
sizeof buf,
input_fp)) != 0)
::fwrite (buf, n, 1, output_fp);

ACE_OS::rewind (input_fp);
ACE_OS::rewind (output_fp);
}

this->tm_.stop ();
return 0;
}

// 5. 使用内存映射文件打开输入文件,使用write 进行文件写操作

int
Mmap1_Test::run_test (int iterations,
FILE *input_fp,
FILE *output_fp)
{
ACE_Mem_Map map_input (fileno (input_fp));
void *src = map_input.addr ();

if (src == MAP_FAILED)
ACE_ERROR_RETURN ((LM_ERROR,
"%s",
this->name ()),
-1);
else
{
this->tm_.start ();

while (--iterations >= 0)
{
if (ACE_OS::write (fileno (output_fp),
src,
map_input.size ()) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%s",
this->name ()),
-1);
ACE_OS::lseek (fileno (output_fp),
0,
SEEK_SET);
}

this->tm_.stop ();
}

if (map_input.unmap () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%s",
this->name ()),
-1);
else
return 0;
}

// 6. 使用内存映射文件打开输入、输出文件, 使用memcpy 进行文件内容的拷贝

int
Mmap2_Test::run_test (int iterations,
FILE *input_fp,
FILE *output_fp)
{
ACE_Mem_Map map_input (fileno (input_fp));
int size = map_input.size ();
ACE_Mem_Map map_output (fileno (output_fp),
size,
PROT_WRITE,
MAP_SHARED);
void *src = map_input.addr ();
void *dst = map_output.addr ();

if (src == MAP_FAILED || dst == MAP_FAILED)
return -1;
else
{
this->tm_.start ();

while (--iterations >= 0)
ACE_OS::memcpy (dst, src, size);

this->tm_.stop ();
}

if (map_input.unmap () == -1
|| map_output.unmap () == -1)
return -1;
else
return 0;
}

很全面的Ace Admin1.3官方文档,包含有最全面的组件及例子,适合急需使用该技术开发的人。 响应式Bootstrap网站后台管理系统模板ace admin,非常不错的轻量级易用的admin后台管理系统,基于Bootstrap3,拥有强大的功能组件以及UI组件,基本能满足后台管理系统的需求,而且能根据不同设备适配显示,而且还有四个主题可以切换。 网页图标全采用FontAwesome,除Bootstrap,jQuery UI使用到的第三方插件有: jQuery 2.0.3 jQuery UI 1.10.3 (Custom Build) Twitter Bootstrap 3.0.0 FontAwesome 3.2.1 Google "Open Sans" Font jQuery Flot Charts 0.8.1 jQuery Sparklines 2.1.2 Easy Pie Chart 1.2.5 jQuery Knob 1.2.0 jQuery Validate 1.11.1 FuelUX 2.3.0 (Spinner & Wizard & Treeview) FullCalendar 1.6.4 jQuery ColorBox 1.4.27 jQuery dataTables 1.9.4 jQuery Chosen 1.0 jQuery Masked Input 1.3.1 jQuery Input Limiter 1.3.1 jQuery AutoSize 1.17.7 Bootstrap Colorpicker Bootstrap Datepicker Bootstrap Timepicker v0.2.3 Bootstrap DateRange Picker 1.2 Bootbox.js 4.0.0 jQuery Gritter 1.7.4 jQuery slimScroll 1.1.1 Spin.js 1.3.0 jQuery UI Touch Punch 0.2.2 Google Code Prettify ExplorerCanvas Mindmup Wysiwyg Editor Toopay Markdown Editor 1.1.4 X-editable 1.4.6 Select2 3.4.2 Bootstrap Tags 2.2.5 jQuery Mobile 1.3.2 (Custom Build) jqGrid 4.5.2 Dropzone.js 3.0 Nestable lists plugin 浏览器兼容: Firefox 5+ Google Chrome 14+ Internet Explorer 8 Internet Explorer 9 Opera 11 Safari 5 Bootstrap兼容: Bootstrap 2.2.x Bootstrap 2.3.x Bootstrap 3.0.x ace admin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值