I have started writing a new chess engine in Swift and now working with the hash table.
In Swift I may simply use an array for the hash table. However IMO that has some drawbacks:
- have to allocate all array items (hash table cells) one by one. It may take time for a huge array
- waste too much memory since for each small items the OS may take some extra memory for managing it
- memory fragment may be so serious
Any solution / idea to deal with hash table in Swift?
Hash table in Swift?
Moderator: Ras
-
phhnguyen
- Posts: 1541
- Joined: Wed Apr 21, 2010 4:58 am
- Location: Australia
- Full name: Nguyen Hong Pham
-
tttony
- Posts: 278
- Joined: Sun Apr 24, 2011 12:33 am
Re: Hash table in Swift?
I've never touched Swift but I was curious in why you can't do it
A quick search gave this: http://stackoverflow.com/questions/2699 ... use-malloc
An it seems that there is no a native way to do it, only bridging like it says in the answer
A quick search gave this: http://stackoverflow.com/questions/2699 ... use-malloc
An it seems that there is no a native way to do it, only bridging like it says in the answer
Skiull http://skiull.blogspot.com
-
kbhearn
- Posts: 411
- Joined: Thu Dec 30, 2010 4:48 am
Re: Hash table in Swift?
a reply in tony's link references another question with a potentially better answer:
http://stackoverflow.com/questions/2600 ... 8#26006918
https://developer.apple.com/reference/s ... blepointer
https://developer.apple.com/reference/s ... 6-allocate
http://stackoverflow.com/questions/2600 ... 8#26006918
https://developer.apple.com/reference/s ... blepointer
https://developer.apple.com/reference/s ... 6-allocate
-
phhnguyen
- Posts: 1541
- Joined: Wed Apr 21, 2010 4:58 am
- Location: Australia
- Full name: Nguyen Hong Pham
Re: Hash table in Swift?
For developing on IDE XCode we can mix code between C, C++, Objective-C and Swift. The links you show me actually suggest to use C++ code for allocating memory.
Yes we can but it is not Swift way.
(Similar, I can re-use all my C++ code in XCode but it is not my purpose of developing an engine in Swift)
Yes we can but it is not Swift way.
(Similar, I can re-use all my C++ code in XCode but it is not my purpose of developing an engine in Swift)
-
phhnguyen
- Posts: 1541
- Joined: Wed Apr 21, 2010 4:58 am
- Location: Australia
- Full name: Nguyen Hong Pham
Re: Hash table in Swift?
Look like UnsafeMutablePointer has some potentials. Reading and trying 