Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在类上使用struct会对允许的数据大小产生影响吗?_Ios_Swift - Fatal编程技术网

Ios 在类上使用struct会对允许的数据大小产生影响吗?

Ios 在类上使用struct会对允许的数据大小产生影响吗?,ios,swift,Ios,Swift,目前,我正在设计一个记笔记的应用程序 其总体使用情况应为: class Note { var title: String? var body: String? } var notes = [Note]() notes.append(Note()) 我很想把笔记设计成结构 struct Note { var title: String? var body: String? } var notes = [Note]() notes.append(Note()

目前,我正在设计一个记笔记的应用程序

其总体使用情况应为:

class Note {
    var title: String?
    var body: String?
}

var notes = [Note]() 
notes.append(Note())
我很想把笔记设计成结构

struct Note {
    var title: String?
    var body: String?
}

var notes = [Note]() 
notes.append(Note())
但是,我也担心这可能会限制

  • 每个Notes实例允许的最大大小。由于音符的弦体大于10MB,这是不常见的
  • 注释结构数组允许的最大数组大小
  • 据我所知,struct的实例是在堆栈内存中创建的,类的实例是在堆内存中创建的。堆栈内存大小比堆内存大小小得多-

    在类上使用struct会影响允许的数据大小吗?

    总之,不会

    结构与类、结构或类数组的最大大小没有区别

    此外,正如Martin在评论中所说,您的结构/类实际上包含指向字符串的指针,而不是字符串本身。因此,结构和类都不会使用不同大小的字符串更改大小

    如前一个问题中所指出的,字符串和数组是固定大小的结构,带有指向堆分配内存的指针,其中包含实际的字符或数组元素。因此,
    struct Note
    的大小是固定的,与字符串中存储的字符数无关。