1
|
Tim Reddy · 技术社区 · 14 年前 |
![]() |
1
3
While this is perfectly acceptable, (its typically how I do it) unless there are more than one chars in a row, alignment issues will force the next variable to waste 1-3 bytes anyway, which could otherwise have been used for free by an int. I encourage you to investigate alignment, its rather straightforward but a little to verbose to explain + consequences here. At any rate, in order to avoid confusion (although I doubt there will be very much, but basically to each their own) you may want to use int8_t or which is typedef-ed to signed char anyway. 编辑:我以前忘记了:MacOS上的malloc实现(也是iOS的基础)只返回16字节或更长的内存块,四舍五入。所以如果你是对象,比如15个字节,你也在浪费一个字节,如果它需要17个字节,你就浪费了15个。 |
![]() |
2
1
In cases like this I usually use a typedef enum containing all valid values:
and write the method like this:
所以代码的用户知道要使用:
这样,如果编译器传递给你其他的东西,你会让他们抱怨。 |
![]() |
3
1
Unless you are going to be creating an awful lot of copies of this numeric attribute, space is not really an issue, even on the iPhone. 更重要的是学习内存管理和基础数据类型(NSCONTROPE,NSCORE,NSCODE等)。 |
![]() |
mikko · SwiftUI如何在不同堆栈中实现同一视图的平滑动画 5 月前 |
![]() |
routern · 如何组合contextMenu和圆角矩形? 5 月前 |
![]() |
DevHome98 · 3D触摸不适用于设备swift 1 年前 |
![]() |
dunoiww · 从全屏返回时如何触发onAppear 1 年前 |
![]() |
Community wiki · iPhone上ivar的继承问题 1 年前 |
![]() |
Community wiki · 查找iOS日历 1 年前 |
![]() |
Community wiki · 有效的IPhone编程技术[关闭] 1 年前 |