Frage

Ich brauche die eine Kohlenstoff-Methode in Kakao zu übersetzen in und Ich habe Probleme, alle Unterlagen zu finden, was die Kohlenstoff-Methode getPtrSize wirklich tut. Aus dem Code, den ich übersetze es scheint, dass es die Byte-Darstellung eines Bild zurückkehrt, aber das wirklich mit dem Namen nicht übereinstimmen. Könnte mir jemand eine gute Erklärung dieser Methode geben oder zu einer Dokumentation verknüpft mich, die es beschreibt. Der Code I genannt MCL in einer Common Lisp Umsetzung setze, die eine Brücke zu Kohlenstoff (I in CCL setze die eine Common Lisp-Implementierung mit einem Cocoa Brücke ist). Hier ist der MCL-Code (#_before einen Methodenaufruf bedeutet, dass es eine Kohlenstoff-Methode ist):

(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))
War es hilfreich?

Lösung

GetPtrSize ist eine Funktion von dem Memory Manager . Wenn Sie Speicher mit NewPtr (eine andere Speicher-Manager-Funktion) zugeordnet ist, würde der Speicher-Manager verfolgen, wie viel Speicher für Sie gefragt, so dass Sie diese Zahl mit GetPtrSize abrufen können.

Der moderne Ersatz für NewPtr ist malloc, die keine solche Funktionalität bereitstellt. Es gibt eine malloc_size Funktion, aber die Zahl kehrt zu einem gewissen Zuwachs kann aufzurunden, so dass es größer sein kann als die Zahl, die Sie ursprünglich gefragt. Sie können sehen, wie das (zumindest vom Konzept her) schlecht sein würde.

Die einzige genaue Ersatz für GetPtrSize ist einfach den Überblick über die Größe der Puffer, um sich selbst.

Alternativ könnten Sie diese Puffer mit NSMutableData Objekte ersetzen. Ein NSMutableData kapselt einen Puffer und seine Größe, so dass es leicht, sie zusammen zu halten.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top