Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-03 Thread Joe Groff via swift-users
> On Oct 3, 2016, at 10:20 AM, Jens Alfke via swift-users > wrote: > > >> On Oct 2, 2016, at 5:14 PM, Mike Ferenduros via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Personally I would be surprised if the malloc caused an actual measurable >> performance hit tbh. > > It won’

Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-03 Thread Jens Alfke via swift-users
> On Oct 2, 2016, at 5:14 PM, Mike Ferenduros via swift-users > wrote: > > Personally I would be surprised if the malloc caused an actual measurable > performance hit tbh. It won’t be noticeable against a call to SecRandom, as noted, but there are other circumstances where it’s a big perform

Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-03 Thread Jean-Denis Muys via swift-users
Indeed, But that function was just an example. I wanted to learn about how to use the stack to call C functions that will fill some memory area passed as a pointer. Jean-Denis > On 3 Oct 2016, at 09:46, Quinn The Eskimo! via swift-users > wrote: > > > On 3 Oct 2016, at 01:14, Mike Ferendu

Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-03 Thread Quinn "The Eskimo!" via swift-users
On 3 Oct 2016, at 01:14, Mike Ferenduros via swift-users wrote: > Personally I would be surprised if the malloc caused an actual measurable > performance hit tbh. Quite. SecRandom generates cryptographically sound random numbers and thus is not optimised for speed. Share and Enjoy -- Quinn

Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-02 Thread Dave Abrahams via swift-users
on Sun Oct 02 2016, Mike Ferenduros wrote: > You can use a local like this: > var x: UInt32 = 0 > withUnsafePointer(to: x) { randomWordPT in > //your existing code here > } > > Or I'm not sure if small arrays go on the heap, but They do. > var bytes: [UInt8] = [0,0,0,0]

Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-02 Thread Mike Ferenduros via swift-users
You can use a local like this: var x: UInt32 = 0 withUnsafePointer(to: x) { randomWordPT in //your existing code here } Or I'm not sure if small arrays go on the heap, but var bytes: [UInt8] = [0,0,0,0] _ = SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes)

Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-02 Thread Dave Abrahams via swift-users
on Sun Oct 02 2016, Jean-Denis Muys wrote: > Hi, > > I have some issues using the new raw memory API. For instance, let's > suppose I want to call the `SecRandomCopyBytes` API to generate a > cryptographically secure random 32-bit number. The difficulty is its 3rd > argument, which is declared a

[swift-users] UnsafeMutablePointer on the stack?

2016-10-02 Thread Jean-Denis Muys via swift-users
Hi, I have some issues using the new raw memory API. For instance, let's suppose I want to call the `SecRandomCopyBytes` API to generate a cryptographically secure random 32-bit number. The difficulty is its 3rd argument, which is declared as UnsafeMutablePointer. Here is a function that does that