Comments (2)
This turned out to be easy - just declare both types as struct
and change the marshaling code to:
public GlyphInfo[] GlyphInfo()
{
int length;
IntPtr glyphInfoPtr = HB.hb_buffer_get_glyph_infos(reference, out length);
var glyphInfos = new GlyphInfo[length];
for (int i = 0; i < length; ++i)
{
glyphInfos[i] = Marshal.PtrToStructure<GlyphInfo>(glyphInfoPtr + 20 * i);
}
return glyphInfos;
}
public GlyphPosition[] GlyphPositions()
{
int length;
IntPtr glyphPositionPtr = HB.hb_buffer_get_glyph_positions(reference, out length);
var glyphPositions = new GlyphPosition[length];
for (int i = 0; i < length; ++i)
{
glyphPositions[i] = Marshal.PtrToStructure<GlyphPosition>(glyphPositionPtr + 20 * i);
}
return glyphPositions;
}
Note: It would be even better to directly marshal the result of HB.hb_buffer_get_glyph_infos()
and HB.hb_buffer_get_glyph_positions()
into c# arrays, thereby avoiding the loop. Haven't figured out how to do that, but seems like a common enough situation so it should be possible. But at least this fixes the issue of allocating lots of tiny classes.
from sharpfont.harfbuzz.
Yes! Good catch! Arrays like this should be possible, my P/Invoke knowledge is a bit rusty but I'll see if I can make it work
from sharpfont.harfbuzz.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharpfont.harfbuzz.