iPhone和Android上的内存对齐 [英] Memory alignment on iPhone and Android

查看:215
本文介绍了iPhone和Android上的内存对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我已经从我的测试中发现了iPhone的malloc有16个字节对齐。但我不知道它是否保证或只是巧合。

As I've discovered from my tests iPhone's malloc has 16 byte alignment. But I'm not sure whether it is guaranteed or just coincidence.

所以,问题是:什么是对iOS和Android(NDK)使用malloc()时,保证内存对齐

So the question is: what is the guaranteed memory alignment when using malloc() on iOS and Android(NDK)?

推荐答案

的malloc使用C返回一个指向一个内存块,这是适合任何类型的变量一致;这一调整是否或将保持在16个字节甚至不同版本的同一操作系统无法得到保证。 Objective-C的有效基于C,所以应该持有如此那里了。

malloc in C returns a pointer to a block of memory "which is suitably aligned for any kind of variable"; whether this alignment is or will remain at 16 bytes is not guaranteed even for different versions of the same OS. Objective-C is effectively based on C, so that should hold true there too.

如果你的Andr​​oid NDK是用C或C ++,同样应持有真实存在。

If your Android NDK is written in C or C++, the same should hold true there.

这篇关于iPhone和Android上的内存对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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