首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getPtrSize法的可可当量碳法

getPtrSize法的可可当量碳法
EN

Stack Overflow用户
提问于 2010-03-09 01:51:44
回答 1查看 197关注 0票数 5

我需要将碳方法转换成可可,但我很难找到任何关于碳方法getPtrSize真正做什么的文档。从我正在翻译的代码看,它似乎返回了图像的字节表示,但这并不真正与名称匹配。有人可以给我一个很好的解释这个方法或链接到一些描述它的文档。我正在翻译的代码是一个名为MCL的常见lisp实现,它具有到carbon的桥梁(我正在翻译成CCL,这是一个带有Cocoa桥的常见lisp实现)。下面是MCL代码(#_before一个方法调用意味着它是一个carbon方法):

代码语言:javascript
复制
(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))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-03-09 02:18:34

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

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

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

或者,您可以用NSMutableData对象替换这些缓冲区。NSMutableData封装了一个缓冲区和它的大小,很容易将它们放在一起。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2403400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档