Skip to content

Conversation

@versi-tech
Copy link
Contributor

Introducing vips_image_write_to_memory support.

Adjusted logic of adding object_unref calls for return types of void* (like with vips_image_write_to_memory). This should not be directly replaced by g_free as memory ownership is not always the same with different API functions of libvips and should be dealt with externally by the client.

@versi-tech versi-tech force-pushed the feature/write_to_memory_support branch from 4254050 to 0c59c52 Compare July 7, 2025 15:08
@lopcode lopcode force-pushed the feature/write_to_memory_support branch from 0c59c52 to b117ea4 Compare July 19, 2025 18:00
@lopcode lopcode force-pushed the feature/write_to_memory_support branch from b117ea4 to 80cb0ec Compare July 19, 2025 18:03
@lopcode
Copy link
Owner

lopcode commented Jul 19, 2025

Thanks again @versi-tech - I took a look at this today, and tweaked it slightly:

  • I realised it's possible to use the MemorySegment API to avoid doing a second copy to/from a ByteBuffer, and I think exposing the FFM API in these advanced functions is OK
  • Rather than free-ing up front, we can use reinterpret to couple the resulting memory to the lifetime of the arena, which is consistent with how all the other operations work
  • Tweaked the VImage.newFromMemory API to also take a MemorySegment rather than byte[] which allows for the same copying optimisation on the other end, and added a VImageFromMemoryToMemory sample to show how that works

@lopcode lopcode merged commit 0d498ab into lopcode:main Jul 19, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants