Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Questions about shared libraries (.so)

Reply
Thread Tools

Questions about shared libraries (.so)

 
 
Paulo da Silva
Guest
Posts: n/a
 
      02-07-2005
Hi.

I am writing a shared library to override some libc
functions.

I have the following questions:

Ex.
int XXX=0;
void f() {++XXX; ...; --XXX;}

1.
Are global data (extern) shared among processes
or threads? If a process or a thread accesses f while
another one is also executing f it sees XXX as 0 or 1?

2.
Is there any problem not freeing malloc allocated areas in f
relying on the automatic free at the end of the job?
I am asking this because I want to share some information
between sucessive calls to f in a process but I don't know what
is the last call. So, I don't know when to free the malloc'ed
areas.

Any links to literature about these is welcome.

Thanks for any help.
 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      02-07-2005
Paulo da Silva wrote:
> Hi.
>
> I am writing a shared library to override some libc
> functions.
>
> I have the following questions:

[snip]

> Any links to literature about these is welcome.
>
> Thanks for any help.


Wrong newsgroup. This newsgroup, news:comp.lang.c,
discusses the _standard_ C language which has no
facilities for shared libraries. These are outside
the scope of the language.

Not all platforms support shared libraries. Please
consult a newsgroup dedicated to your platform.
Many newsgroups are listed in the FAQs below.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

 
Reply With Quote
 
 
 
 
Lawrence Kirby
Guest
Posts: n/a
 
      02-07-2005
On Mon, 07 Feb 2005 16:41:55 +0000, Paulo da Silva wrote:

> Hi.
>
> I am writing a shared library to override some libc
> functions.
>
> I have the following questions:
>
> Ex.
> int XXX=0;
> void f() {++XXX; ...; --XXX;}
>
> 1.
> Are global data (extern) shared among processes
> or threads?


That would depend on the implementation and how it implements processes
and thread which are not C concepts. Typically however threads share the
same address space whereas processes for normal operations don't.

Given your reference ot .so lubraries comp.unix.prorgammer might be a
better place to discuss this.

> If a process or a thread accesses f while
> another one is also executing f it sees XXX as 0 or 1?


That would depend on when XXX is accessed. Also consider makin XXX
volatile.

> 2.
> Is there any problem not freeing malloc allocated areas in f relying on
> the automatic free at the end of the job?


That depends on what you mean by a "job". You should free memory when you
no longer need it or else you might have a memory leak. On reasonable
systems the memory allocated by a program is reclaimed when the program
terminates.

> I am asking this because I
> want to share some information between sucessive calls to f in a process
> but I don't know what is the last call. So, I don't know when to free
> the malloc'ed areas.


If it is a single allocation that's not too large that may not be a
problem, you might think of it like a static variable.

Lawrence
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
standard libraries don't behave like standard 'libraries' Sriram Srinivasan Python 13 11-12-2009 06:05 PM
Using mandatory libraries (custom class loading vs. expanding libraries) Karsten Wutzke Java 21 06-29-2007 09:25 PM
JVM and shared libraries Dave Neary Java 13 03-24-2005 04:44 PM
Parsing Native shared libraries thomas.smith@cox.net Java 0 02-18-2005 02:52 PM
Shared libraries on dotnet Tascien ASP .Net 1 07-24-2004 02:59 AM



Advertisments