in reply to Re^4: OT: Why does malloc always give me 24?
in thread OT: Why does malloc always give me 24? [SOLVED]

Maybe what ikegami meant was that the underscore is not needed. Struct names live in a different namespace, so you can write
typedef struct host host;

Of course, I recommend much longer struct names since C namespace is so limiting. I usually name my stuff with a project identifier prefix, like struct myproj_host. I find CamelCase and lowercase equally appealing for the prefix and object names, but tend to stick to one pattern per project. I often put a suffix of _t on my typedefs, and _p on pointer typedefs, but that would also make the CTL library generate ugly code. Whoops I just looked it up, and "_t" are reserved. So I guess I won't do that anymore. Sometimes I don't declare any typedefs and just live with 'struct' declared everywhere. It isn't pretty, but C is never really pretty and it helps document the code for people less familiar with it. I suppose the typedefs are required for that library you're using though, and with it putting prefixes on your type names for the container name that is only going to look OK with lowercase...

Maybe if the CTL library were written in cpppp it would be easier to parameterize the output :-)

(that vector class isn't finished; but maybe CTL would make a good model to base my eventual set of standard templates on)

Replies are listed 'Best First'.
Re^6: OT: Why does malloc always give me 24?
by karlgoethebier (Abbot) on Aug 20, 2024 at 08:49 UTC
      If you mean multiple threads calling into the same data structure, I don't blame them. That's a mess of platform complications and potential runtime overhead. I've pulled out enough hair over that model of programming to permanently switch to "each thread gets its own data, and they exchange ownership of the whole structure via passing a pointer through a pipe". This model plays very nicely with Perl, too.

      Thanks for the tips on additional libraries to investigate.

        "…each thread gets its own data”

        That is probably the obvious.

        ”…they exchange ownership of the whole structure via passing a pointer through a pipe"

        Any links to instructive examples are gladly accepted.

        Links for thread victims:

        Update: Perhaps a solution?

        Update 2: …seems to be incomplete…last update 10 years ago or so