转换的指针在C数组++ [英] Convert a pointer to an array in C++

查看:112
本文介绍了转换的指针在C数组++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CreateFileMapping函数返回一个指向内存映射文件,我想对待那个内存映射为一个数组。

The CreateFileMapping function returns a pointer to a memory mapped file, and I want to treat that memory mapping as an array.

下面就是我基本上想要做的:

Here's what I basically want to do:

char Array[] = (char*) CreateFileMapping(...);

除了显然我不能简单地挥动手臂,并宣布一个指针现在是一个数组。

Except apparently I can't simply wave my arms and declare that a pointer is now an array.

难道你们有什么想法,我该怎么办呢?我不想复制指针指向到数组中的值,因为这将使用过多内存,大文件。

Do you guys have any idea how I can do this? I don't want to copy the the values the pointer is pointing to into the array because that will use too much memory with large files.

多谢,

推荐答案

您不需要。你可以索引的指针,如果它是一个数组:

You do not need to. You can index a pointer as if it was an array:

char* p = (char*)CreateFileMapping(...);
p[123] = 'x';
...

这篇关于转换的指针在C数组++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆