简体   繁体   English

内存分配 - Arduino

[英]Memory Allocation - Arduino

I'm new to this low level stuff. 我是这个低级别的新手。 I'm currently learning arduino. 我正在学习arduino。 I'm currently using an Arduino Mega 2560 and in our course we are practicing memory management. 我目前正在使用Arduino Mega 2560,在我们的课程中我们正在练习内存管理。 I'm a pro at memory management in pc but somehow I'm having crazy problems here in arduino. 我是电脑中的内存管理专家,但不知怎的,我在arduino中遇到了疯狂的问题。 For instance: 例如:

The arduino have 8192B, I'm trying to overflow it with uint_16 so I made an array of 8192/16 which is 512. so I did arduino有8192B,我试图用uint_16溢出它所以我做了一个8192/16的数组,这是512.所以我做了

uint16_t A[512+1];

Well I expected that to cause an overflow. 好吧,我希望这会导致溢出。

What is wrong with my concept? 我的概念出了什么问题?

You seem to be confusing your bits for your bytes. 你似乎把你的位混淆了你的字节。

Assuming sizeof (uint16_t) is 2 on the Arduino, your array of 513 16-bit integers uses only 1026 bytes, which easily fits. 假设Arduino上的sizeof (uint16_t)为2,那么513个16位整数的数组仅使用1026个字节,这很容易适合。

Also in Arduino when the memory is full, you don't get any error or warning. 当内存已满时,在Arduino中,您不会收到任何错误或警告。 The microcontroller just restarts. 微控制器刚刚重启。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM