CreateManagedLibraryExpression
creates a managed library expression by applying f to a positive integer ID associated with a registered manager with name mname.
Details

- The IDs generated for the manager with name mname start at 1 and follow sequentially until the manager is unregistered.
- A manager is registered by using the LibraryLink callback function registerLibraryExpressionManager.
Examples
Basic Examples (1)Summary of the most common use cases
Load example LibraryFunction objects that implement a simple linear congruential random generator:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-4s3oex
Create an instance of a linear congruential generator:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-eky732

Set its parameters using the unique ID assigned by CreateManagedLibraryExpression:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-mbgn2e
Generate two pseudorandom numbers from the instance:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-byhn50

Set up another instance and generate three numbers from it:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-r19fk1

The first instance is available until the expression is no longer referenced:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-cew139

The history expression Out will often keep references to an expression you may not be aware of. Extra references like this can be prevented by setting $HistoryLength=0 either in a session or inside of Block:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-hlt9d9

The variable g3 is the only reference to the managed library instance, so when g3 is unset, the library instance is freed and expressions with this ID will no longer work:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-bpzmeo

Note that the same does not work for g1 because it is referenced by Out:

https://wolfram.com/xid/0tgrjb3f1rpr1god1hua-l5d0v4

Wolfram Research (2014), CreateManagedLibraryExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html.
Text
Wolfram Research (2014), CreateManagedLibraryExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html.
Wolfram Research (2014), CreateManagedLibraryExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html.
CMS
Wolfram Language. 2014. "CreateManagedLibraryExpression." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html.
Wolfram Language. 2014. "CreateManagedLibraryExpression." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html.
APA
Wolfram Language. (2014). CreateManagedLibraryExpression. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html
Wolfram Language. (2014). CreateManagedLibraryExpression. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html
BibTeX
@misc{reference.wolfram_2025_createmanagedlibraryexpression, author="Wolfram Research", title="{CreateManagedLibraryExpression}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html}", note=[Accessed: 03-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_createmanagedlibraryexpression, organization={Wolfram Research}, title={CreateManagedLibraryExpression}, year={2014}, url={https://reference.wolfram.com/language/ref/CreateManagedLibraryExpression.html}, note=[Accessed: 03-June-2025
]}