可可等效碳方法的getPtrSize
-
18-09-2019 - |
题
我需要将碳方法转化为可可成,我无法找到什么碳方法getPtrSize确实任何文件。从代码我正在翻译它似乎返回图像的字节表示,但并没有真正匹配了这个名字。可能有人给我这个方法的一个很好的解释或链接我描述它的一些文档。我翻译的代码是在一个名为MCL一个Common Lisp实现具有桥碳(我翻译成CCL这是一个Common Lisp实现与可可桥)。下面是MCL代码(#_before方法调用意味着它是一个碳法):
(defmethod COPY-CONTENT-INTO ((Source inflatable-icon)
(Destination inflatable-icon))
;; check for size compatibility to avoid disaster
(unless (and (= (rows Source) (rows Destination))
(= (columns Source) (columns Destination))
(= (#_getPtrSize (image Source))
(#_getPtrSize (image Destination))))
(error "cannot copy content of source into destination
inflatable icon: incompatible sizes"))
;; given that they are the same size only copy content
(setf (is-upright Destination) (is-upright Source))
(setf (height Destination) (height Source))
(setf (dz Destination) (dz Source))
(setf (surfaces Destination) (surfaces Source))
(setf (distance Destination) (distance Source))
;; arrays
(noise-map Source) ;; accessor makes array if needed
(noise-map Destination) ;; ;; accessor makes array if needed
(dotimes (Row (rows Source))
(dotimes (Column (columns Source))
(setf (aref (noise-map Destination) Row Column)
(aref (noise-map Source) Row Column))
(setf (aref (altitudes Destination) Row Column)
(aref (altitudes Source) Row Column))))
(setf (connectors Destination)
(mapcar #'copy-instance (connectors Source)))
(setf (visible-alpha-threshold Destination)
(visible-alpha-threshold Source))
;; copy Image: slow byte copy
(dotimes (I (#_getPtrSize (image Source)))
(%put-byte (image Destination) (%get-byte (image Source) i) i))
;; flat texture optimization:
;; do not copy texture-id
;; -> destination should get its own texture id from OpenGL
(setf (is-flat Destination) (is-flat Source))
;; do not compile flat textures: the display list overhead
;; slows things down by about 2x
(setf (auto-compile Destination) (not (is-flat Source)))
;; to make change visible we have to reset the compiled flag
(setf (is-compiled Destination) nil))
解决方案
GetPtrSize
距离内存管理器功能一>。当你与NewPtr
(另一个内存管理器功能)分配的内存,内存管理器将保持多少内存要求的轨道,让你可以检索与GetPtrSize
该号码。
在现代替代NewPtr
是malloc
,它提供没有这样的功能。有一个malloc_size
功能,但它返回的数量可以四舍五入到一些增量,所以它可能比你问原来的数目。你可以看到这将是(至少在概念上)不好。
的唯一准确替代GetPtrSize
是简单地跟踪缓冲器的大小的自己。
另外,您也可以替换NSMutableData对象这些缓冲区。一个NSMutableData封装了一个缓冲器,其大小,使其容易保持在一起。
不隶属于 StackOverflow