将指针转换为C ++中的数组 [英] Convert a pointer to an array in C++
问题描述
CreateFileMapping函数返回一个指向内存映射文件的指针,我想将该内存映射视为一个数组。
这里是我基本想要做的:
char Array [] =(char *)CreateFileMapping
除了显然我不能简单地挥动我的手臂,并声明一个指针现在是一个数组。 / p>
你们有什么想法我该怎么做吗?我不想将指针指向的值复制到数组中,因为这将对大文件使用太多的内存。
感谢一堆, p>
您不需要。您可以将指针索引为一个数组:
char * p =(char *)CreateFileMapping ;
p [123] ='x';
...
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.
Thanks a bunch,
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屋!