2010-03-08 3 views
5

카본 메서드를 코코아로 변환해야하고 탄소 메서드 getPtrSize가 실제로하는 작업에 대한 문서를 찾는 데 어려움이 있습니다. 코드에서 이미지의 바이트 표현을 반환하지만 실제로 이름과 일치하지 않는 것 같습니다. 누군가가 나에게이 방법에 대한 좋은 설명을 주거나 그것을 설명하는 문서에 연결시켜 줄 수 있습니까? 번역 할 코드는 탄소에 대한 다리가있는 MCL이라는 일반적인 리스프 구현에 있습니다. (CCL로 변환하는 것은 코코아 브리지를 사용하는 일반적인 리스프 구현입니다.) (a 메소드 호출은 탄소 방법임을 의미 #_before) 여기 MCL 코드 :카본 메서드와 동일한 코코아 메서드 getPtrSize

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

이것은 사실입니까? +1 내 마음을 불고. –

답변

4

GetPtrSizeMemory Manager의 함수이다. NewPtr (다른 메모리 관리자 기능)으로 메모리를 할당하면 메모리 관리자가 요청한 메모리 양을 추적하여 GetPtrSize으로 그 번호를 검색 할 수 있습니다.

NewPtr의 현대 대체품은 이러한 기능을 제공하지 않는 malloc입니다. malloc_size 함수가 있지만 반환하는 숫자는 약간의 증가로 반올림 될 수 있으므로 원래 요청한 숫자보다 클 수 있습니다. 당신은 이것이 (적어도 개념적으로) 나쁜 방법을 알 수 있습니다.

GetPtrSize에 대한 정확한 대체는 단순히 버퍼 크기를 추적하는 것입니다.

또는 이러한 버퍼를 NSMutableData 개체로 바꿀 수 있습니다. NSMutableData는 버퍼와 그 크기를 캡슐화하므로 쉽게 유지할 수 있습니다.

관련 문제