Cocoa 相当于 Carbon 方法 getPtrSize

发布于 2024-08-24 12:14:20 字数 2226 浏览 7 评论 0原文

我需要将carbon 方法翻译成cocoa ,但我很难找到有关carbon 方法getPtrSize 真正作用的任何文档。从我正在翻译的代码来看,它似乎返回图像的字节表示形式,但这与名称并不真正匹配。有人可以给我这个方法的一个很好的解释,或者将我链接到一些描述它的文档。我正在翻译的代码位于一个称为 MCL 的通用 lisp 实现中,该实现具有到 Carbon 的桥(我正在翻译为 CCL,它是带有 Cocoa 桥的通用 lisp 实现)。这是MCL代码(方法调用之前的#_表示它是一个carbon方法):

(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))

I need to translate the a carbon method into cocoa into and I am having trouble finding any documentation about what the carbon method getPtrSize really does. From the code I am translating it seems that it returns the byte representation of an image but that doesn't really match up with the name. Could someone give me a good explanation of this method or link me to some documentation that describes it. The code I am translating is in a common lisp implementation called MCL that has a bridge to carbon (I am translating into CCL which is a common lisp implementation with a Cocoa bridge). Here is the MCL code (#_before a method call means that it is a carbon method):

(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))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黄昏下泛黄的笔记 2024-08-31 12:14:20

GetPtrSize 是来自 的函数内存管理器。当您使用 NewPtr(另一个内存管理器函数)分配内存时,内存管理器将跟踪您请求的内存量,以便您可以使用 GetPtrSize 检索该数字。

NewPtr 的现代替代品是 malloc,它不提供此类功能。有一个 malloc_size 函数,但它返回的数字可能会向上舍入到某个增量,因此它可能大于您最初要求的数字。你可以看到这(至少在概念上)是多么糟糕。

GetPtrSize 唯一准确的替代方法就是自己跟踪缓冲区的大小。

或者,您可以用 NSMutableData 对象替换这些缓冲区。 NSMutableData 封装了缓冲区及其大小,从而可以轻松地将它们保持在一起。

GetPtrSize is a function from the Memory Manager. When you allocated memory with NewPtr (another Memory Manager function), the Memory Manager would keep track of how much memory you asked for, so that you could retrieve that number with GetPtrSize.

The modern replacement for NewPtr is malloc, which provides no such functionality. There is a malloc_size function, but the number it returns may be rounded up to some increment, so it may be greater than the number you asked for originally. You can see how that would be (at least conceptually) bad.

The only accurate replacement for GetPtrSize is simply to keep track of the sizes of the buffers yourself.

Alternatively, you might replace these buffers with NSMutableData objects. An NSMutableData encapsulates a buffer and its size, making it easy to keep them together.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文