Do not use AllocHGlobal when creating copies

Open
#1,230 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Refactor
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp
Domain
tooling

Research direction

Start by locating the AllocHGlobal and FreeHGlobal uses involved in conversion operators, then inspect how copies and the internal structure are represented. Compare the proposed managed C# field approach with the current ownership behavior; done requires an agreed design that avoids leaving users responsible for freeing copied memory.

Written by the indexing model from the issue text.

Description

enhancement

The problem is that such memory must always be freed with FreeHGlobal but it's difficult for the user to always do so. Conversion operators are an example. Instead of AllocHGlobal, we could use a regular managed C# field of type the internal structure. There are problems such as this field being allocated as soon as declared since it's a struct, which is inefficient, but it needs to be at least considered.

Dominant language
C#
Stars
3.4k
Forks
541
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mono/CppSharp

All issues in mono/CppSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.