how can i wrap static variables?

M

mwebel

Hi,
i am using a function from a C library which happens to use a lot of
static variables and functions.
The library used to be a executable but was turned into dll library.

My problem is that while i can call this function a first time... a
second time call will crash.
It seems that static values or functions are not fully reseted at the
end of each call.

I thought of two options:
-Hard, time consuming one: try to clean by hand on the C code, which
is very complex. and i am most likely to break something.(i already
tried but its really complex)
- Seemingly easy: wrap the function in a "protected zone"?

I though of option 2 as being able to wrap the function so it kinda
receives its own memory space with a brand new set of variables
everytime it is called. It might be a bit of a waste of memory but
since its only a couple of MB and i need it like mostly 2 or three
times: thats ok.

sofar i tried creating a class which wraps around that one function...
like:

class Function{
int myfunct( int param, Obj param2{
dllfunct(param, param2)
}
}


then creating an object for every call and then destroying it before
the second call.... but the static are still there(which of course is
sometimes the purpose of using them).


so are there any other things i might try?
thanks for any Ideas!
 
I

Ian Collins

Hi,
i am using a function from a C library which happens to use a lot of
static variables and functions.
The library used to be a executable but was turned into dll library.
Then you will be better of posting to a windows programming group.
 
M

mwebel

Ian said:
Then you will be better of posting to a windows programming group.

Hi, i did post it to a windows group too.. hoping for answers regarding
threading.
But since modularity is a part of C++ as well i think the library can
be seen as just a separate module code (i hope im right assuming this).

Actually i want to port this to linux too.. so i would be happier if i
found a way of solving this without going too deep into OS dependent
code.
Thats why i posted in here.
And also because everytime i post here i get quite nice answers too! :)
 
I

Ian Collins

Hi, i did post it to a windows group too.. hoping for answers regarding
threading.
But since modularity is a part of C++ as well i think the library can
be seen as just a separate module code (i hope im right assuming this).

Actually i want to port this to linux too.. so i would be happier if i
found a way of solving this without going too deep into OS dependent
code.
Thats why i posted in here.
And also because everytime i post here i get quite nice answers too! :)
Fair enough, maybe you can rephrase the question avoiding references to
DLLs :)

What exactly is the problem, you mention static functions and variables,
which by design have local scope to their compilation unit, so how can
you call them form outside? Perhaps post some code that illustrates the
problem.
 
S

Steve Pope

i am using a function from a C library which happens to use a lot of
static variables and functions.
The library used to be a executable but was turned into dll library.

My problem is that while i can call this function a first time... a
second time call will crash.
It seems that static values or functions are not fully reseted at the
end of each call.

That's the whole idea of a static variable -- that you don't
reset it after each call. Assuming it's the flavor of static
variable that's inside of a function.

S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top