F
F
FlameArt2018-06-03 17:41:13
C++ / C#
FlameArt, 2018-06-03 17:41:13

Can a C++ library store state when connected to the main C# project?

I want to write a parser as a C++ dll and connect it to the main C# project. But between the parses, you need to store several arrays so as not to receive them every time from the site, and use them in the same C ++ parser during the next calls to the parse function. In short: is a C++ dll a set of static functions, or can it hold state? Or for what I want some other approaches are used?
Is it possible to do this without passing these arrays each time from C# to C++ function? Those. so that the library stores them somewhere in its memory and sometimes accesses them. They are large and a lot of resources will be spent on constant transmission. If I wrote everything in C#, I would just import the parser class and create an instance of it in my memory, but I'm new to C++ and I don't know how it will behave, or how to do it differently.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2018-06-03
@FlameArt

Maybe.
In the library, the DllMain() function is called when the library is loaded and unloaded. When loading, you initialize the necessary resources, when unloading, you clear them. In between, use it.
You can declare the state as a global (relative to the library) structure/class that will contain the necessary data.
If you pass these arrays to the library from an external program (and not the library itself receives them), then keep them with you until the end of the work. It is enough to pass pointers to them (links) to the library, and no heap of resources will be spent.

A
Alexander Taratin, 2018-06-03
@Taraflex

https://ru.stackoverflow.com/questions/327136/sing...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question