articles icon indicating copy to clipboard operation
articles copied to clipboard

question about MemoryLayout

Open ghost opened this issue 1 year ago • 3 comments

Hi! I'm learning a lot from your examples and articles.

After a long time reading up on Panama project I can't come up with a memory layout made up of a string (up to 100 characters) and an integer number. I need to define a sequence of records with two fields (name and age).

Your example from devox talk is a 4 character string (the tick of the share), so you can use an integer! but that's not my case!

thanks in advance

have a nice week

ghost avatar Jan 09 '24 19:01 ghost

Do you mean 100 bytes when the string is decoded?

MemoryLayout.sequenceLayout(100, JAVA_BYTE).withName("name") might do the trick.

minborg avatar Jan 15 '24 10:01 minborg

Thanks for your reply! I mean at most 100 bytes (could be less). The string represent a city name in my example. Not sure if its possible when the length is not a constant...

ghost avatar Jan 18 '24 08:01 ghost

You could always encode the length separately if you want. Take a look at the method Arena.allocateFrom(String str)

minborg avatar Jan 18 '24 09:01 minborg