Skip to content

Conversation

huming2207
Copy link

Hi all,

This commit resolves the first part of the feature request #3857 . Now users can bring their own allocator by using meson setup builddir -Dcustom_allocator_header=/path/to/your_own_alloc.h, and then provide the TVG_{MALLOC|CALLOC|REALLOC} macros.

However I haven't got a chance to override the allocator for the 3rd party libraries like those JPG and PNG loaders. I will implement those later when I have some time.

Regards,
Jackson

@huming2207 huming2207 requested a review from hermet as a code owner October 1, 2025 06:29
@github-actions github-actions bot added infrastructure Dev infrastructure renderer Core rendering labels Oct 1, 2025
@huming2207 huming2207 force-pushed the feature/custom-allocator branch from fd32c38 to 2b5849f Compare October 1, 2025 07:19
@hermet hermet added the enhancement Improve features label Oct 1, 2025
@hermet hermet requested a review from Copilot October 1, 2025 07:40
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Implements custom memory allocator support for ThorVG, allowing users to override default malloc/free functions by specifying a custom header file via meson configuration. This addresses the first part of feature request #3857.

  • Adds a new tvgAllocator.h header that defines TVG_* memory allocation macros with fallback to standard library functions
  • Updates the memory allocation wrapper functions in tvgCommon.h to use the new TVG_* macros instead of std:: functions
  • Introduces a meson build option custom_allocator_header for specifying custom allocator implementations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/renderer/tvgAllocator.h New header defining TVG_* memory allocation macros with custom allocator support
src/renderer/tvgCommon.h Updated to use TVG_* macros instead of std:: memory functions
meson_options.txt Added custom_allocator_header option for specifying custom allocator header path
meson.build Added configuration logic for custom allocator feature and build summary

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@hermet hermet added feature New feature additions and removed enhancement Improve features labels Oct 1, 2025
This commit resolves the first part of the feature request thorvg#3857 .

User in theory can bring their own allocator by using `meson setup builddir -Dcustom_allocator_header=/path/to/your_own_alloc.h`, and then provide the TVG_{MALLOC|CALLOC|REALLOC} macros.
@huming2207 huming2207 force-pushed the feature/custom-allocator branch from 2b5849f to 69dd9f2 Compare October 1, 2025 07:54
@huming2207
Copy link
Author

@hermet Done, please proceed review, thanks

@huming2207
Copy link
Author

Here's an example of ESP-IDF port: https://github.com/huming2207/esp-thorvg

But somehow if the multithreading is enabled and the tvg_engine_init() is called in the main task, it will crash due to pthread can't recognise the thread ID. This might be a bug on ThorVG or ESP-IDF side. I will submit a bug report a bit later.

Meanwhile @hermet could you please re-run the CI? I think the previous one was failed due to some sort of time out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature additions infrastructure Dev infrastructure renderer Core rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants