如何读/写类型值从" RAW"内存用C? [英] How to read/write type values from "raw" memory in C?
本文介绍了如何读/写类型值从" RAW"内存用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何做这样的事的?
void *的内存=的malloc(1000); //分配一个内存池
*(存储器+ 10)= 1; //在字节10集的整数值
INT I = *(内存+ 10); //读取从10个字节的整数值
解决方案
简单的例子:把内存为unsigned char类型的数组
void *的内存=的malloc(1000); //分配一个内存池
uint8_t有* PTR =内存+ 10;
* PTR = 1 //设置一个整数的字节值10
uint8_t有I = * PTR; //读取从10个字节的整数值
您可以使用整数太大,但你一定要注意你是在一次设置的字节数量。
How do I make something like this work?
void *memory = malloc(1000); //allocate a pool of memory
*(memory+10) = 1; //set an integer value at byte 10
int i = *(memory+10); //read an integer value from the 10th byte
解决方案
Easy example: treat the memory as an array of unsigned char
void *memory = malloc(1000); //allocate a pool of memory
uint8_t *ptr = memory+10;
*ptr = 1 //set an integer value at byte 10
uint8_t i = *ptr; //read an integer value from the 10th byte
You can use integers too, but then you must pay attention about the amount of bytes you are setting at once.
这篇关于如何读/写类型值从" RAW"内存用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文