-
-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
enhancementNew feature or requestNew feature or request
Description
From developer.apple.com/ManagedBufferPointer/Capacity:
This value may be nontrivial to compute; it is usually a good idea to store this information in the “header” area when an instance is created.
Under the hood
From ManagedBuffer.swift:
extension ManagedBufferPointer {
@inlinable
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
public var capacity: Int {
return (
_capacityInBytes &- ManagedBufferPointer._elementOffset
) / MemoryLayout<Element>.stride
}
}Where _capacityInBytes is defined as malloc_size:
static inline __swift_size_t _swift_stdlib_malloc_size(const void *ptr) {
extern __swift_size_t malloc_size(const void *);
return malloc_size(ptr);
}Solutions
- Store additional member
capacity: IntinHeader. Header size: 2 words. - Pack
capacityinside existing header. Header size: 1 word. Layout[1bit - isNegative][31 bits - count][32 bits - capacity]
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request