Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006829OCamlstandard librarypublic2015-04-02 22:432016-12-06 16:28
Reporterdbuenzli 
Assigned Tofrisch 
PrioritynormalSeverityfeatureReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.02.1 
Target VersionFixed in Version4.04.0 
Summary0006829: Add Gc.value_{word,byte}_size : 'a -> int
DescriptionIt would be nice to have a function in the standard library that allows to get the size of an arbitrary value. This is useful when trying alternate encodings and/or data structures e.g. to minimise in-memory representations of a particular data set.

For now to get a quick estimation I sometimes simply marshal the value to a string, or resort to ad-hoc functions that perform the count on the datastructure at hand e.g.:

https://github.com/dbuenzli/uucp/blob/master/src/uucp_cmap.ml#L57-L63 [^]
https://github.com/dbuenzli/uucp/blob/master/src/uucp_rmap.ml#L60-L66 [^]
https://github.com/dbuenzli/uucp/blob/master/src/uucp_tmap.ml#L39-L56 [^]
https://github.com/dbuenzli/uucp/blob/master/src/uucp_tmapbool.ml#L53-L65 [^]

But could we maybe rather have something like Jean-Christophe Filliatre's size functions [1] directly in the Gc module ?

Thanks,

Daniel

[1] https://www.lri.fr/~filliatr/ftp/ocaml/ds/size.ml.html [^]
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0013646)
ygrek (reporter)
2015-04-06 17:17

see also http://www.bytebucket.org/gds/objsize.git [^]
(0014052)
doligez (administrator)
2015-06-11 20:22

Any implementation will basically be a rewrite of the `Marshal` functions, so we probably should just modify the marshalling primitives to have an option to output only the size.
(0014072)
frisch (developer)
2015-06-15 10:54
edited on: 2015-06-15 10:54

I think it would be cleaner to create a new function instead. The body of the marshal function, i.e. extern_rec in byterun/extern.c is quite small, and if we keep only the logic to count the size, it would be even smaller (e.g. we don't need to handle various cases for "small integers" or "short strings"; and one can merge cases String_tag/Double_tag/Double_array_tag/Custom_tag).

(0015847)
dbuenzli (reporter)
2016-04-25 21:51

GPR https://github.com/ocaml/ocaml/pull/560 [^]

- Issue History
Date Modified Username Field Change
2015-04-02 22:43 dbuenzli New Issue
2015-04-06 17:17 ygrek Note Added: 0013646
2015-06-11 20:22 doligez Note Added: 0014052
2015-06-11 20:22 doligez Status new => acknowledged
2015-06-15 10:54 frisch Note Added: 0014072
2015-06-15 10:54 frisch Note Edited: 0014072 View Revisions
2016-04-25 21:51 dbuenzli Note Added: 0015847
2016-12-06 16:28 frisch Status acknowledged => resolved
2016-12-06 16:28 frisch Fixed in Version => 4.04.0
2016-12-06 16:28 frisch Resolution open => fixed
2016-12-06 16:28 frisch Assigned To => frisch
2017-02-23 16:43 doligez Category OCaml standard library => standard library


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker