Slashdot Mirror


APR 1.0.0 Goes Gold

cliffwoolley writes "After several years of development, the Apache Portable Runtime, which is the portability library underlying the Apache HTTP Server 2.x, has finally reached its own 1.0.0 release. If you want to write a portable app without the headaches, APR is the way to do it. Grab a copy and check it out. The full announcement is here."

17 of 111 comments (clear)

  1. APR by cbrocious · · Score: 4, Interesting

    APR is quite interesting, but there are many existing libraries out there that duplicate the features. Any comparisons out there between APR and things like SDL?

    --
    Disconnect and self-destruct, one bullet at a time.
    1. Re:APR by Electrum · · Score: 4, Informative

      Any comparisons out there between APR and things like SDL?

      APR is for servers, SDL is for games.

    2. Re:APR by FooAtWFU · · Score: 4, Insightful

      I don't think APR and SDL have much of the same market. The Apache Portable Runtime is used in the Apache httpd. Simple DirectMedia Layer is used for graphics and sounds and the link.

      --
      The World Wide Web is dying. Soon, we shall have only the Internet.
    3. Re:APR by cbrocious · · Score: 4, Informative

      But SDL provides cross-platform threading and such. It's been used in many things other than just games (which is why it's not just sound and video)

      --
      Disconnect and self-destruct, one bullet at a time.
    4. Re:APR by Anonymous Coward · · Score: 5, Interesting
      Other notable portable runtimes include:

      NSPR (Netscape Portable Runtime) http://www.mozilla.org/projects/nspr/index.html

      ACE (Adaptive Communication Environment http://www.cs.wustl.edu/~schmidt/ACE.html

      wxWidgets http://www.wxwidgets.org

      Those are just a few, there are others out there as well

      Choosing one to use is a difficult exercise. The important things to consider are what you want to use it for and how it fits in with your existing software and experience.

      If you'll be doing GUI programming, wxWidgets is a good way to go. In addition to the file io/threads/networking portability you get GUI portability as well. The NSPR fits into this area as well.

      The APR is obviously a well tried and proven framework, since the Apache HTTP server uses it. If you want cross platform server software, APR is probably a good choice. NSPR fits in this area as well.

      The biggest consideration when choosing one of these libraries is how well you can pick it up and understand it. If you look at the API and it doesn't make any sense to you, it won't be pleasant to integrate with it. Documentation varies in quantity and quality. Also, how well supported is the library by the development community?. (Actually not much of an issue for APR,NSPR and wxWidgets as they are all very actively maintained and used).

      On another note, it certainly would be nice to get more of a standardized set of cross platform libraries on the scale of the Java API. There's no reason why this can't be done. Most of the pieces are already out there. It's too bad someone hasn't yet taken the effort to integrate all of this stuff into a super library for GUI, networking, io, threads, email, video, blah blah blah...

      Perhaps I'll have to get started on that...
  2. Re:java-ish? by dollargonzo · · Score: 4, Informative

    this a C library, not a virtual machine/language like jvm/java. the idea is not to have code run without recompile on all platforms, but rather that *all* you need is a recompile. more specifically, you don't need to have platform specific cases in your code. code becomes pretty unmaintainable when it is littered with #ifdefs

    --
    BSD is for people who love UNIX. Linux is for those who hate Microsoft.
  3. Re:glib? by DylanQuixote · · Score: 5, Informative

    glib didn't exist at the time the APR was started. Also glib is still not quite useful on windows.

  4. Re:glib? by E-Lad · · Score: 4, Informative

    You have the wrong idea of what APR is.

    APR is a library which, at its basic level, provides wrapper functions to syscalls of many different operating systems. Why? because the same syscall on one OS sometimes behaves differently, have bugs, or take slightly different arguments from the same syscall on other OSes.

    APR addresses these differences and provides you, the app developer, with a common set of functions.

    So if you're say coding your own FTP server project and you main development platform is linux or what have you, if you use APR's wrtite() or APR's sendfile(), you know that your call to that will also work on Solaris, FreeBSD, Darwin, etc... because APR takes care of all the abstraction at compile time. /dale

  5. Re:glib? by Anonymous Coward · · Score: 5, Interesting
    APR is a library which, at its basic level, provides wrapper functions to syscalls of many different operating systems. Why? because the same syscall on one OS sometimes behaves differently, have bugs, or take slightly different arguments from the same syscall on other OSes.

    All true. But you didn't mention the other huge thing it does - pools. They're a completely different way of managing memory than other systems use. The Apache people would say they're higher-performance (more locality -> better cache behavior, big groups of stuff can be deallocated at once, etc.), less error-prone (fewer leaks), etc.

    And then a bunch of pool-using code. Like string functions that replace the standard C strcpy() and such but return new pool-allocated strings rather than potentially overflowing a buffer.

  6. apr_pool_t by multipartmixed · · Score: 4, Interesting

    > Does anyone know why Apache didn't just use glib?

    Does glib provide pools-based memory allocation for all its functions?

    Somehow, I doubt they do. To me, a good pool-based allocator that handles *everything* is really, really, really freakin' handy. Not only is it cross-platform, but code tends to suffer from fewer memory-allocation-related defects (such as using freed pointers, leaking core, leaking descriptors, etc).

    Of course, you have to design your code properly from the outset to take full advantage of hierarchical pools. Apache 1.3 (and presumably 2.x -- I haven't studied the source) are *excellent* examples of code designed to take advantage of pools, and the HTTP request model is almost naturally suited for it as well. Write a few complex modules in C some time, you'll see what I mean.

    Now, if only I could could figure out why the APR hash functions are so slow for large tables..

    --

    Do daemons dream of electric sleep()?
  7. Some info on APR ... by pikine · · Score: 5, Informative

    First of all, APR is not a virtual machine or bytecode interpreter like that of .NET common language runtime or JVM. APR is a library (collection of functions) written in C, for C programs. It contains a lot of wrappers to the real standard C library functions, because some conventions of standard library still varies from OS to OS.

    For example, the path separator is different in Unix ("/"), Windows ("\"), MacOS (":" - pre X, but also Finder in OS X). Another example is loading dynamically linked libraries (DSO in APR speech). Yet another example is threads.

    Besides wrappers, APR has its own memory management routines. APR also adds utility functions not found in the standard library, such as hash table.

    By the way, it would be helpful if someone can post a comparison between NSPR (netscape portable runtime) and APR.

    --
    I once had a signature.
    1. Re:Some info on APR ... by DrXym · · Score: 4, Informative
      The NSPR offers similar functionality. Info about the NSPR is here.

      I'm guessing by this stage that both the APR and NSPR are industrial strength libs to write cross-platforms against. Both have similar functionality because both underpin web servers (yes NSPR is used by the AOL/Sun iPlanet webserver, and not just Mozilla).

      What it might boil down to in the end is which runtime's licence is most compatible with what you have in mind.

  8. Multi-threading isn't that simple by xyote · · Score: 5, Interesting
    The atomic operations while nice are basically useless without memory visibility rules or semantics. This is something that get discussed a lot on comp.programming.threads. I suppose you can assume they are there but that's assuming a lot.

    Also, doing condvars on windows isn't that easy as Douglas Schmidt writes up here.

    Writing portable thread libraries seems to be a popular activity. It would be nice if the authors of those packages documented that they were aware of the issues as a first step in convincing those of us who know about those issues that they know what they are doing. Yeah, I know that the Apache authors are considered experts, but it wouldn't be the first time some rather well known experts got tripped up on multi-threading.

  9. Interested, but confused by Apache License 2.0 by Anonymous Coward · · Score: 4, Interesting

    I'm interested in using the library but confused by the terms of the license.

    If I *statically* link to the APR in a commercial software product, what are the consequences? Especially when the commercial software is distributed in binary form only.

    http://www.apache.org/licenses/LICENSE-2.0

  10. Follow up - I took a quick look at the source. by xyote · · Score: 5, Insightful
    For the atomic operations, the intel based code is ok since the lock prefix serializes memory. The powerpc load reserved / store conditional do not however and explicit memory barriers are required and they are not there. That's bad.

    For the win32 version of condvar, I don't think a win32 Event isn't going to hack it. The current logic allows a condvar to remain signaled until the all waiters have woken up and have decremented the use count to zero. This could lead to a lot of spurious wakeups if some waiting thread takes it time to wake up. The APR authors need to read that Schmidt document I mentioned earlier and maybe also look at Schmidt's ACE project and see how he did it.

    This is not a comprehensive critique as I only took a cursory look but what I did see indicates that APR needs some more work.

  11. Re:Yet another library for an obsolete language by Billly+Gates · · Score: 4, Informative

    Unfortunatly g++ is not a good c++ compiler so all the Unix nerds look at the size of the compiled program and time to execute and assume the problem is with C++ itself and then continue to work in C.

    There is alot of anti c++ sentiment in the unix community because of that.

  12. Pools have problems (was Re:apr_pool_t) by Ristretto · · Score: 5, Interesting
    Ugh. Although pools are plenty useful, they have lots of problems. The inability to free individual objects can be a real deal-breaker. Since you can't free objects within a pool until all of them are no longer in use, dead memory can just accumulate. For lots of reasonable situations, this means unbounded memory consumption. It also makes it very hard to incorporate existing code that uses malloc/free.

    I wrote a paper about this, and problems with custom (special-purpose) memory allocators in general, called Reconsidering Custom Memory Allocation (OOPSLA 2002). In it, I also describe a new memory allocation scheme, called reaps . This is a hybrid of regions (pools) and heaps that acts just like pools except you can still free individual objects.

    In fact, for a case study, I put reaps into Apache (adding a ap_pfree call), and showed how using reaps made it simple to incorporate a piece of existing C code (namely, bc) into Apache. Without reaps, an invocation consumed 7.4MB of memory (since every free had to be disabled). With reaps, 240KB.

    I did send a message to the Apache folks about this a while back, but they balked because the implementation is in C++, rather than C (developed with my Heap Layers infrastructure)...

    -- emery

    Emery Berger
    Assistant Professor
    Dept. of Computer Science
    University of Massachusetts, Amherst