Slash Boxes

All the Perl that's Practical to Extract and Report

More | Login | Reply
Loading... please wait.
  • I'm using C in school again. Lots to relearn ... I was under the impression you can't truly return a struct or any complicated data structure that didn't boil down to a basic data type or pointer, but apparently I was wrong.

    Passing and returning structs has been around since the ANSI C standardization in the 80's, I think. The GNU compiler of the day was one of the first to provide that extension but it was fairly common. I can recall one compiler, perhaps it was pcc, allowing only structs that were small enough to fit in a long to be passed around. (So, a struct with one short and two chars could be passed as a unit.)

    And suddenly I'm learning more about malloc() than ever before. There are things I'd heard about but never investigated in detail, because I always knew I could look them up if I needed to. Tonight I had to look up the mallinfo() function (which I presume is a GNU extension) in order to report on how much memory malloc was using.

    I guess mallinfo is a GNU and/or Linux extension, I've never heard of it.

    Anyway, I saw something in the GNU libc manual that mentioned sbrk, which if I understand correctly is the assembly instruction (or very low level C function) used in some way to implement malloc(), and I decided that while my long program was running its next trial, I could look through and learn how that works. But I got distracted along the way when I saw obstacks, which I'd never heard of before, and sounded interesting because they appear to represent an alternative to malloc().

    sbrk is a Unix system call. It extends the upper limit of the memory image so that your data segment has more space. It gets called(under the hood) by malloc when there isn't enough memory already available in the data image to fulfill the requested allocation.