Re: [swift-users] Object size on heap

2016-03-23 Thread Howard Lovatt via swift-users
Thanks, you are correct. Very helpful. -- Howard. On 24 March 2016 at 11:20, Kate Stone wrote: > You’re almost certainly seeing side effects of not keeping the instance of > TestClass alive long enough for the unsafe pointer to still refer to an > allocated malloc block. A quick REPL session

Re: [swift-users] Object size on heap

2016-03-23 Thread Kate Stone via swift-users
You’re almost certainly seeing side effects of not keeping the instance of TestClass alive long enough for the unsafe pointer to still refer to an allocated malloc block. A quick REPL session illustrates this fact: 1> class TestClass { 2. let a = 0 3. let b: Int? = nil 4. }

Re: [swift-users] Object size on heap

2016-03-23 Thread Howard Lovatt via swift-users
@Kate, I don't seem to be able to get `malloc_...` to work. EG: class TestClass { let a = 0 let b: Int? = nil } @_silgen_name("swift_class_getInstanceExtents") func swift_class_getInstanceExtents(theClass: AnyClass) -> (negative: UInt, positive: UInt) print("swift_class_getInstanceExtents

Re: [swift-users] Object size on heap

2016-03-23 Thread Kate Stone via swift-users
I definitely concur that tools like Instruments are the best way to understand the impact of decisions on memory across the board. For fine-grained inquiries about memory use you can also rely on malloc family functions to make inquiries: let required_size = malloc_size(unsafeAddressOf(object_r

Re: [swift-users] Object size on heap

2016-03-23 Thread Howard Lovatt via swift-users
Thanks, I will give that a try -- Howard. On 24 March 2016 at 03:17, Jens Alfke wrote: > > On Mar 22, 2016, at 11:04 PM, Howard Lovatt via swift-users < > swift-users@swift.org> wrote: > > I am writing custom collection classes and trying to assess which one is > better, both in terms of perf

Re: [swift-users] Object size on heap

2016-03-23 Thread Jens Alfke via swift-users
> On Mar 22, 2016, at 11:04 PM, Howard Lovatt via swift-users > wrote: > > I am writing custom collection classes and trying to assess which one is > better, both in terms of performance and memory usage. Won't be used in > 'real' code, just to guide development. You might consider using hea

Re: [swift-users] Object size on heap

2016-03-22 Thread Howard Lovatt via swift-users
I am writing custom collection classes and trying to assess which one is better, both in terms of performance and memory usage. Won't be used in 'real' code, just to guide development. -- Howard. On 23 March 2016 at 03:52, Jordan Rose wrote: > > On Mar 22, 2016, at 8:47, Joe Groff via swift-u

Re: [swift-users] Object size on heap

2016-03-22 Thread Howard Lovatt via swift-users
Many thanks -- Howard. On 23 March 2016 at 02:47, Joe Groff wrote: > > On Mar 21, 2016, at 9:31 PM, Howard Lovatt > wrote: > > How do you call swift_class_getInstanceExtents, it doesn't show in Xcode? > > > It's not provided as API by default. You can do this as an unsupported > hack: > > @_

Re: [swift-users] Object size on heap

2016-03-22 Thread Jordan Rose via swift-users
> On Mar 22, 2016, at 8:47, Joe Groff via swift-users > wrote: > > >> On Mar 21, 2016, at 9:31 PM, Howard Lovatt > > wrote: >> >> How do you call swift_class_getInstanceExtents, it doesn't show in Xcode? > > It's not provided as API by default. You can do this

Re: [swift-users] Object size on heap

2016-03-22 Thread Joe Groff via swift-users
> On Mar 21, 2016, at 9:31 PM, Howard Lovatt wrote: > > How do you call swift_class_getInstanceExtents, it doesn't show in Xcode? It's not provided as API by default. You can do this as an unsupported hack: @_silgen_name("swift_class_getInstanceExtents") func swift_class_getInstanceExtents(the

Re: [swift-users] Object size on heap

2016-03-21 Thread Howard Lovatt via swift-users
How do you call swift_class_getInstanceExtents, it doesn't show in Xcode? -- Howard. On 22 March 2016 at 06:07, Joe Groff wrote: > > > On Mar 19, 2016, at 1:53 PM, Howard Lovatt via swift-users < > swift-users@swift.org> wrote: > > > > Hi, > > > > Is there a way to find out how big an object

Re: [swift-users] Object size on heap

2016-03-21 Thread Joe Groff via swift-users
> On Mar 19, 2016, at 1:53 PM, Howard Lovatt via swift-users > wrote: > > Hi, > > Is there a way to find out how big an object is on the heap? No public API yet. For entertainment purposes, you could use the runtime's swift_class_getInstanceExtents function, passing in the class object for t

Re: [swift-users] Object size on heap

2016-03-21 Thread Brent Royal-Gordon via swift-users
>> Is there a way to find out how big an object is on the heap? > > Yes, the sizeof() function. I think he's asking for the size of the object itself. For a reference type, `sizeof()` gives you the size of the reference. -- Brent Royal-Gordon Architechies _

Re: [swift-users] Object size on heap

2016-03-21 Thread Jens Alfke via swift-users
> On Mar 19, 2016, at 4:53 PM, Howard Lovatt via swift-users > wrote: > > Is there a way to find out how big an object is on the heap? Yes, the sizeof() function. —Jens___ swift-users mailing list swift-users@