Cocoa 可可碳当量法getPtrSize
我需要将碳方法转换成可可,我很难找到任何关于碳方法getPtrSize真正作用的文档。从我翻译的代码来看,它似乎返回了图像的字节表示,但这与名称并不匹配。有人能给我一个很好的解释这个方法或链接到一些文档,描述它。我正在翻译的代码是在一个名为MCL的公共lisp实现中,它有一个到carbon的桥(我正在翻译成CCL,它是一个带有Cocoa桥的公共lisp实现)。以下是MCL代码(方法调用之前的#59u表示它是一个carbon方法):Cocoa 可可碳当量法getPtrSize,cocoa,lisp,common-lisp,macos-carbon,Cocoa,Lisp,Common Lisp,Macos Carbon,我需要将碳方法转换成可可,我很难找到任何关于碳方法getPtrSize真正作用的文档。从我翻译的代码来看,它似乎返回了图像的字节表示,但这与名称并不匹配。有人能给我一个很好的解释这个方法或链接到一些文档,描述它。我正在翻译的代码是在一个名为MCL的公共lisp实现中,它有一个到carbon的桥(我正在翻译成CCL,它是一个带有Cocoa桥的公共lisp实现)。以下是MCL代码(方法调用之前的#59u表示它是一个carbon方法): GetPtrSize是来自的函数。当您使用NewPtr(另一个内
GetPtrSize
是来自的函数。当您使用NewPtr
(另一个内存管理器功能)分配内存时,内存管理器将跟踪您请求的内存量,以便您可以使用GetPtrSize
检索该数字
NewPtr
的现代替代品是malloc
,它不提供此类功能。有一个malloc_size
函数,但它返回的数字可能会向上舍入到某个增量,因此它可能大于您最初要求的数字。你可以看到这是多么糟糕(至少在概念上是如此)
GetPtrSize
唯一准确的替代方法就是自己跟踪缓冲区的大小
或者,您可以使用NSMutableData对象替换这些缓冲区。NSMutableData封装了缓冲区及其大小,便于将它们放在一起。这是真的吗+谢谢你让我大吃一惊。
(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))