Hi Etan,
`withMemoryRebound` does not copy memory.
The proposal for UnsafeRawPointer contains information about the memory model
(as related to pointers):
https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md
(also, the method is defined in the following file:
h
Moving to swift-users. (swift-dev to BCC; swift-dev is for compiler
development.)
It's also important to know about the methods available on NSString, which
are exposed on the String type when you import Foundation:
https://developer.apple.com/reference/foundation/nsstring
You might also be inter
Thanks once more!
It all depends on how withMemoryRebound works.
If there is any way where it actually copies the bound memory to a separate
place, then passes that copy to the closure,
it would not be a good idea to write past the end of the bound memory.
If withMemoryRebound is a simple cast
Ah, ok.
In that case, I believe it is correct because sockaddr_storage is in fact big
enough to hold either the IPv4 or IPv6 structure.
When bits go unused, that causes no harm. And when “addr” goes out of scope, it
will be completely deallocated, so no memory leak either.
Regards,
Rien
Site:
I meant the question in a more generalized sense.
The sockaddr example is just one that is easily understandable :-)
Thanks for the link though, interesting read!
> On 29 Dec 2016, at 14:47, Rien wrote:
>
> I used the code from
> http://blog.obdev.at/representing-socket-addresses-in-swift-usi
I used the code from
http://blog.obdev.at/representing-socket-addresses-in-swift-using-enums/ in my
package SwifterSockets (see github link below)
It does not answer your question exactly, but I think it is a rather better
approach to sockaddr usage.
Regards,
Rien
Site: http://balancingrock.n
Hi,
When calling POSIX accept, the common way is to
sockaddr_storage addr = {0};
sockaddr_len addrlen = 0;
int clientFd = accept(serverFd, (sockaddr *) &addr, &addrlen);
In Swift, this translates to
var addr = sockaddr_storage()
var addrlen = sockaddr_len(0)
int clientFd = withUnsafeMutablePointe
As to the why question: (just guessing here)
By the time the compiler want to know what type will be in the array, it cannot
do so. The enum is a generic and thus without full type information (it only
has partial type information).
Regards,
Rien
Site: http://balancingrock.nl
Blog: http://swif
I think you made your type (enum) unnecessary complex, the following works:
protocol Element {
}
enum ElementNode {
case element(Element)
case empty
}
var childElements = [ElementNode]()
Regards,
Rien
Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http:
Wow, that works :-) Updated the repo.
However, when the system module is missing, I still get "header not found"
errors instead of the suggestion of installing the package via brew.
BTW: It may be nice if you could update your blog post to get rid of the
absolute path in the modulemap as well:
10 matches
Mail list logo