   /// idea to store this information in the "header" area when
   /// an instance is created.
   public final var capacity: Int {
-    let p = ManagedBufferPointer<Header, Element>(self)
-    return p.capacity
+    let storageAddr = UnsafeMutableRawPointer(Builtin.bridgeToRawPointer(self))
+    let endAddr = storageAddr + _swift_stdlib_malloc_size(storageAddr)
+    let realCapacity = endAddr.assumingMemoryBound(to: Element.self) -
+      firstElementAddress
+    return realCapacity
+  }
+
+  internal final var firstElementAddress: UnsafeMutablePointer<Element> {
+    return UnsafeMutablePointer(Builtin.projectTailElems(self,
+                                                         Element.self))
+  }
+
+  internal final var headerAddress: UnsafeMutablePointer<Header> {
+    return UnsafeMutablePointer<Header>(Builtin.addressof(&header))
   }
 
   /// Call `body` with an `UnsafeMutablePointer` to the stored

  public final func withUnsafeMutablePointers<R>(
    _ body: (UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R
  ) rethrows -> R {
    return try ManagedBufferPointer(self).withUnsafeMutablePointers(body)
  }

  /// The stored `Header` instance.

      ManagedBuffer<Header, Element>) throws -> Header
  ) rethrows -> ManagedBuffer<Header, Element> {

    let p = Builtin.allocWithTailElems_1(
         self,
         minimumCapacity._builtinWordValue, Element.self)

    let initHeaderVal = try factory(p)
    p.headerAddress.initialize(to: initHeaderVal)
    // The _fixLifetime is not really needed, because p is used afterwards.
    // But let's be conservative and fix the lifetime after we use the
    // headerAddress.
    _fixLifetime(p) 
    return p
  }

  /// The actual number of elements that can be stored in this object.
