473,473 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how can i wrap static variables?

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!

Dec 2 '06 #1
4 1468
mw****@freenet.de wrote:
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.

--
Ian Collins.
Dec 2 '06 #2

Ian Collins wrote:
>used to be a executable but was turned into dll library.
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! :)

Dec 2 '06 #3
mw****@freenet.de wrote:
Ian Collins wrote:
>>>used to be a executable but was turned into dll library.

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! :)
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.

--
Ian Collins.
Dec 2 '06 #4
<mw****@freenet.dewrote:
>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.
Dec 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: James | last post by:
Hello Java NG, I not sure if this is the right NG for this type of question but if not please let me know which is, TIA Any way first off let me say I'm a student and this WAS last weeks lab,...
9
by: Bryan Parkoff | last post by:
I have noticed that C programmers put static keyword beside global variable and global functions in C source codes. I believe that it is not necessary and it is not the practice in C++. Static...
5
by: name | last post by:
Back for more critique. ---------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #define MAX 10000
8
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx...
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
3
by: FUGATO | last post by:
I need to help to wrap up text. I have a line all the text and I need to wrap the text with 40 characters each line but without using function. Somebody help me about that and give me an idea
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
2
by: =?Utf-8?B?Y2hyaXNiZW4=?= | last post by:
Hi, I have some C++ static library which I would like to wrap and use in C# applications. It appears that I have two options. 1. Wrap the static library as dynamic library (dll), use unmanaged...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.