How to know if malloc.h is available?

unix

    Next

  • 1. Linux Multithreading
    Hi, Im trying to create a modular program. The user uses a console, and depending what the user types, different modules(groups of functions) become active, like a normal shell. This can be done by using threads, however, all the modules must be compiled together into the program, to allow me to specify what initial function is associated with the thread. I would like the program to be able to load new modules from file, to allow me to expand the available modules, without recompiling everything. I realize I could use IPC or something similar to communicate among a whole bunch of processes, but then control of when which process executes is passed to the OS and I'd like to control it myself. Is there a way to start threads using programs from file? Is there a better way to do this. In the end, I want to be able to load and unload modules (including new modules from file), and have them share information with each other. If one module requests information, another module can reply. Also if one module has higher priority it gets execution time before another. Any thoughts would be appreciated, Bart
  • 2. lock on the keymap
    Hey, An application A is running in the Linux text console and it modifies the console keymap. How can it lock the modified keymap so no other application changes it as long as A is running? A C-code snippet would be appreciated. Thanks. john
  • 3. How can I make all child processes die with the parent?
    Hi Is there any way in the C API to override the default inherited-by-init behaviour when a parent process dies leaving behind children and grandchildren? Is there a way of making sure the entire process tree from the parent downwards dies when the parent exits? I'm thinking it must be possible in some simple way (yes I realise I could get the parent to manually kill all its children but that seems pretty ugly) since for example when an xterm dies the shell it spawned and any processes the shell in turn spawned die too. Thanks for any help B2003
  • 4. glade
    hi; iam developing gui with Gtk; i have some images and html main pages; can i call directly the html pages while developing with Gtk;(can i use the html pages while developing with glade). is there any mechanism available for this; thank u; sri;
  • 5. signal creation
    hi; iam creating gui with glade; i want to have some examples for developing in glade; mainly when button event is activated related frame has to be poped up.(example to do this). can i call html in to glade. where can i get examples for developing gui application using glade, which will include events creation, signals, callbacks etc. thank u; sri;

How to know if malloc.h is available?

Postby fogli_beppe » Fri, 21 Nov 2008 05:40:48 GMT

Hi,
is there a way to know if the header file malloc.h is available?
I mean, is there some cpp macro to test, like for example
macros defined in standards or specifications like SVID, XPG,
POSIX,...
or unix flavour like __sun?
I have this piece of code:

#if defined (__sun) || defined (__i386) || defined (__ia64)
#include <malloc.h>
#define HAVE_MALLINFO
#endif

It compiles on linux (x86, x86_64 and itanium) and on Solaris (SPARC)
but it doesn't compile on Mac OS X (x86), where the compiler (gcc from
XCode 3.1.1) can't find malloc.h .
Now, I'm pretty new with Mac but I think the test above should make
use of "more portable" macros.

Thanks for your help.

Re: How to know if malloc.h is available?

Postby Lew Pitcher » Fri, 21 Nov 2008 06:10:12 GMT

On November 19, 2008 15:40, in comp.unix.programmer,  XXXX@XXXXX.COM 



[snip]

Well, that's the cannonical test for whether or not malloc.h is available to
the compiler.

Now, two things:
1) For the compiler to be /complete/, it /must/ include a malloc.h header.
So, go back and check the install for the compiler to see if it missed
something.

2) While there is no /requirement/ (at the C compiler level) that <malloc.h> 
actually be a file in your filesystem, most Unixish systems populate
the /usr/include directory with flat files for all the standard (C and
POSIX) headers. If there is a file for malloc.h, you'd find it there.



-- 
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
 http://www.**--****.com/ | GPG public key available by request
----------      Slackware - Because I know what I'm doing.          ------



Re: How to know if malloc.h is available?

Postby Lew Pitcher » Fri, 21 Nov 2008 06:17:00 GMT

On November 19, 2008 16:10, in comp.unix.programmer, Lew Pitcher





Oops... let me correct that. 
For the compiler to be complete, it must include malloc() and friends. The
header for the malloc() family of functions is <stdlib.h>, not <malloc.h>. 

-- 
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
 http://www.**--****.com/ | GPG public key available by request
----------      Slackware - Because I know what I'm doing.          ------



Re: How to know if malloc.h is available?

Postby Doug McIntyre » Fri, 21 Nov 2008 06:31:31 GMT

Lew Pitcher < XXXX@XXXXX.COM > writes:






And Darwin (MacOSX) does have malloc() defined in stdlib.h, and also
has a /usr/include/malloc/malloc.h header file. 

Probably a throwback to its Mach roots. 





Re: How to know if malloc.h is available?

Postby gordonb.1mzml » Fri, 21 Nov 2008 08:37:28 GMT

>1) For the compiler to be /complete/, it /must/ include a malloc.h header.

Incorrect.  Standard C makes no mention of such a header.
The correct header for malloc() and related functions is <stdlib.h>.

FreeBSD has an interesting <malloc.h> header, which suggests that
it's probably a bad idea to use <malloc.h>, and an even worse idea
to assume that its presence implies the existence of mallinfo():

/* $FreeBSD: src/include/malloc.h,v 1.5 2001/11/07 23:14:31 obrien Exp $ */
#if __STDC__
#error "<malloc.h> has been replaced by <stdlib.h>"
#else
#include <stdlib.h>
#endif



Re: How to know if malloc.h is available?

Postby fogli_beppe » Sat, 22 Nov 2008 01:35:37 GMT

Thanks to everyone for the answers.
Probably I've been a little too short in my first message.

On the Mac OS X I installed all of the package XCode 3.1.1 from Apple
which provides
gcc 4.2 beside a lots of other development tools.
I think this is a /complete/ installation of the compiler and so of
the standard headers too.
The malloc.h is not an ISO C standard header so it's not part of the
compiler.
I think it should be provided by the system, for example the GNU C
Library provide a
malloc.h containing mallinfo . I can't find a usable malloc.h on the
Mac even though
there are 2 malloc.h in /usr/include (malloc/malloc.h and sys/
malloc.h) none
containing mallinfo.

Searching a bit on the net I found that mallinfo should be provided by
SVID/XPG
compliant systems (GNU Lib C malloc.h and manual).
Under Solaris 8 mallinfo is in malloc.h and the man page for mallinfo
says that
prototypes for malloc(), calloc(), realloc() and free() are also
provided in malloc.h
for compatibility with old applications, but new application should
include
<stdlib.h> which has no mallinfo.
The SVID 4th edition ( http://www.**--****.com/ ) says
that it's use
is deprecated because it would be removed in later version of the
definition (probably
for ISO C compatibility).
I'm not an expert about unix standards and definitions but I'm
wondering if
there exist some ccp macro like _XOPEN_*, _XPG_*, _POSIX_* or the like
to test for checking the availability of malloc.h/mallinfo .







Re: How to know if malloc.h is available?

Postby Nate Eldredge » Sat, 22 Nov 2008 04:55:12 GMT

reformatted your paragraphs to make them easier to read.

XXXX@XXXXX.COM writes:


Let's step back for a minute.

malloc() and free() are ISO standard C and should exist everywhere. In
pre-ISO days, some systems put their prototypes in malloc.h, but the
correct place for them according to ISO C is stdlib.h, and all modern
systems should comply with this, Mac OS X included. The ISO standard
does not mention malloc.h at all.

mallinfo() is a non-ISO function which provides some statistics about
memory allocations. On SYSV-derived systems (to which SVID applies),
its prototype is located in the non-ISO malloc.h header.

But Mac OS X is based on BSD, so I wouldn't expect it to comply with
SVID. I suspect it doesn't provide mallinfo() at all, and it may not
have a malloc.h header either. This is not a deficiency in the
compiler; you're trying to hold it to a standard that it doesn't claim
to support.

I'm not aware of a standard predefined macro to test for mallinfo() or
malloc.h. It appears that Solaris defines __SVR4 which might be good
enough, since any system that defines it is claiming to be SYSV like,
and should thus have mallinfo(). However, the usual way to handle this
sort of thing is to test for it in a configuration stage before starting
to compile. A tool like GNU autoconf is typical; its configure script
could check for headers like malloc.h and the existence of functions
like mallinfo, then create a header file containing macros like
HAVE_MALLINFO that indicate whether they exist.

So in short: your system probably doesn't have mallinfo() or malloc.h,
so you're going to have to alter the code not to use it in your case.
(This should be easy since the values it returns are purely
informational.) If you want to automatically detect whether a system
has these features, you'll have to deal with that yourself, but there
exist tools that can help.


Re: How to know if malloc.h is available?

Postby Arch Stanton » Sat, 22 Nov 2008 07:01:59 GMT

The one platform where you need malloc.h is Windows (yes, I know the 
name of this newsgroup but still, many people need Windows portability). 
So I would think that

#ifdef _WIN32
#include <malloc.h>
#endif

would be sufficient and appropriate. That's what I do.

Regarding mallinfo, that's more complex. Maybe you could just declare it 
yourself.

AS

Re: How to know if malloc.h is available?

Postby fogli_beppe » Sat, 22 Nov 2008 07:05:23 GMT




Thanks a lot!


OK, this was clear to me. My previous message can be confusing,
I wrote it in a hurry... I apologize.


This is the point! I'm looking for a cpp macro that can detect
whether the system is SVID compliant or, the other way round,
that can detect a system based on BSD like Mac OS X, which
is supposed not to have malloc.h/mallinfo.
I'm not looking necessarily for a macro specific to malloc.h/mallinfo.
This was what I meant with "more portable" in my first message.
The way it is now seems not to work with system based on BSD
on i386/ia64 platforms.

Thanks for the hints about __SVR4. I'm going to investigate if
it is what I need.


I agree! Tools like autoconf really simplify your life,
but the code I'm talking about doesn't use such tools.
Believe me or not, it hasn't even a makefile!
It's a single monolitic source file, 1.6 MB - 60000 lines
of C code!


I already bypassed the problem and compiled the program, simply
commenting out the inclusion of malloc.h and the definition
of HAVE_MALLINFO. It works fine.
But I'm looking for a definitive solution to give some feedback to the
maintainer.

Thanks a lot again!

Similar Threads:

1.I know that I am a google troll.

 XXXX@XXXXX.COM  (Another google troll) writes:

> But I know that Linux is my salvation.

I'm going to come up with some universal kill file for all news
readers, none of these google/hotmail/yahoo/aol accounts are for real
anyway. 

2.I know I am an idiot.

> Peter Klmann

At last.  I've found one.

-- 
Diogenes Laertius

3.I know that I am a homo.

I Roy Culley admit that I am a homo, stalking, Linux fool and that I
like little boys pee pee's.
I admit that I wack off to compilers and little boy pictures.
I am sorry that I am so sick but I know that I need help and pleas
contact me so that I can move forward instead of always moving
backward allowing that penis to insert inside me.
I admit that I enjoy the warm feeling of a real man's sperm filling my
poopy hole.
But I know that Linux is my salvation.
Help me, Roy Culley.
I, Roy am a homo.

Roy Culley

4.dont know who i am anymore :(

Peter Klmann < XXXX@XXXXX.COM > wrote:

> I can't shake this feeling from my head.

5.MALLOCTYPE user: malloc replacement calling default malloc?

I would like to monitor calls to malloc/free/etc via the MALLOCTYPE
user: malloc replacement mechanism.  But i just want to monitor them,
not re-implement them.  Is there a way to call the default malloc
routines from a user defined malloc handler?  Just calling malloc()
gives the expected infinite recursion, since malloc calls get
redirected to the user defined malloc replacement!

Are they available via other symbols such as malloc_y_heap or similar
that I could refer to directly in my replacement module?

6. way of calling malloc() inside __malloc__ hooks

7. query: How to know the total heap size available for pthreads in linux

8. ANY BODY KNOW ABOUT SITE WHERE THE NOTES OF EMBEDDED IS AVAILABLE



Return to unix

 

Who is online

Users browsing this forum: No registered users and 62 guest