Determine size of array Protocol.Type in memory

Viewed 39

I am trying to find out what the size of a protocol type array in memory is. But I lack the tools to figure out how to retrieve the size. It doesn't make sense that the object size of an object with 3 protocol type constants is more than the size of a class of an array of protocol Types. Is it possible that these protocol types arrays are not stored in the heap and therefore are not tracable?

enum TestEnum1: TestProtocol {
    static func hello() {
        print("hello")
    }
}

enum TestEnum2: TestProtocol {
    static func hello() {
        print("hello")
    }
}

enum TestEnum3: TestProtocol {
    static func hello() {
        print("hello")
    }
}

enum TestEnum4: TestProtocol {
    static func hello() {
        print("hello")
    }
}

class ProtocolTypeArrayInClassTest {
        let testEnumArray: [TestProtocol.Type] = [TestEnum1.self, TestEnum2.self, TestEnum3.self, TestEnum3.self, TestEnum3.self, TestEnum3.self, TestEnum3.self, TestEnum3.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self,TestEnum1.self]
    }
class ProtocolTypeInClassTest {
    let testEnum: TestProtocol.Type = TestEnum1.self
    let testEnum2: TestProtocol.Type = TestEnum2.self
    let testEnum3: TestProtocol.Type = TestEnum3.self
}

in main 

print("heapSize of protocolTypeInClassTest object \(MemoryLayout.size(ofValue: ProtocolTypeInClassTest()))")

        print("Instancesize of protocolTypeInClassTest object \(class_getInstanceSize(type(of: ProtocolTypeInClassTest())))")
        print("heapSize of protocolTypeArrayInClassTest object
print("heapSize of protocolTypeArrayInClassTest object \(MemoryLayout.size(ofValue: ProtocolTypeArrayInClassTest()))")

        print("Instancesize of protocolTypeArrayInClassTest object \(class_getInstanceSize(type(of: ProtocolTypeArrayInClassTest())))")

heapSize of protocolTypeInClassTest object 8

Instancesize of protocolTypeInClassTest object 64

heapSize of protocolTypeArrayInClassTest object 8

Instancesize of protocolTypeArrayInClassTest object 24

0 Answers
Related