0

I have my initial variable.

let videoImage:CIImage = CIImage(cvPixelBuffer: pixelBuffer)

I create another buffer likeso.

let newImage:CIImage = self.videoImage

I print them out to look at their memory address

print(videoImage)
print(newImage)

Output:

Optional(<CIImage: 0x280b91260 extent [0 0 1128 1504]>
  affine [1 0 0 -1 0 1504] extent=[0 0 1128 1504]
    colormatch "QuickTime 'nclc' Video (1,1,6)"_to_workingspace extent=[0 0 1128 1504]
      IOSurface 0x28073d990(675) seed:47 BGRA8 extent=[0 0 1128 1504]
)
<CIImage: 0x280b91260 extent [0 0 1128 1504]>

It seems that they have the same memory address. 0x280b91260

Is there a way to create a new variable with the same exact information but with a different memory address?

For example

Optional(<CIImage: 0x280b91260 extent [0 0 1128 1504]>
  affine [1 0 0 -1 0 1504] extent=[0 0 1128 1504]
    colormatch "QuickTime 'nclc' Video (1,1,6)"_to_workingspace extent=[0 0 1128 1504]
      IOSurface 0x28073d990(675) seed:47 BGRA8 extent=[0 0 1128 1504]
)
<CIImage: 0x361a92348 extent [0 0 1128 1504]>

Where the first and second are a copy but the first has a memory address 0x280b91260 and the second 0x361a92348 for example?

impression7vx
  • 1,728
  • 1
  • 20
  • 50

1 Answers1

1

CIImage is a class. A class is a reference type. Assignment of a class instance simply assigns the value of the pointer. To put it another way, assignment simply gives two pointers to the same object (your 0x280b91260). That is what a reference type is. See Is Swift Pass By Value or Pass By Reference.

If you want a copy, say self.videoImage.copy().

matt
  • 515,959
  • 87
  • 875
  • 1,141