Mail Archives: djgpp/1998/08/27/17:02:11
In <35E1C842 DOT 45EFF366 AT newnorth DOT net>, Mike Rusch <ruschtmm AT newnorth DOT net> writes:
>In my program, I define a structure reptfmt as follows:
>
>struct reptfmt {
> char numfields;
> char numsorts;
> char **fnames;
> fieldinfo *fields;
> sortinfo *sorts;
> char groups;
>} ;
You forgot to tell us what "sortinfo" and "fieldinfo" is. I assume they are ints, just
like what any tolerant compiler would do... :)
If these datatypes are more complex than that, I would like to know.
> [...]
Your code worked fine here, both with GCC for DJGPP and GCC for EMX (OS/2).
Borland C++ 3.1 for DOS gave me compiler errors (!).
But I think that is Borland's fault.
How does your code that calls reptfmtcpy() look like? Maybe you're doing
something strange there?
As far as I can see, your code looks OK.
>Sometimes I need a copy of a reptfmt structure. Since var1 = var2
>doesn't make copies of the data pointed to by fnames, fields, and sorts,
>I had to write a special function called "reptfmtcpy":
I would rather advise you to make a class, instead of a struct, and then make
a copy constructor.
>So, what do I do? From the traceback it almost looks like "new" calls
>malloc, but this seems strange to me since new is supposed to be a
>keyword, and supposedly more efficient than malloc. I suppose I could
>use malloc instead, but then I'd have to change all my new's to malloc's
>and my delete's to free's. Plus, who knows if malloc would work any
>better?
I've never heard that "new" should be more efficient than malloc(). I beleive
that "new" was invented in order to make memory allocation a part of the
C++ language, not just a library function. It made it easier for the programmer,
but program execution hasn't necessarily become more efficient.
Am I wrong?
--
---- Morten Stenshorne, Gommerud, 3320 Vestfossen, NORWAY ----
-- mstensho AT powertech DOT no -- http://home.powertech.no/mstensho/ --
---- Computer Engineer -- Phone: 93440112 -- Doofuz AT IRCNet ----
Veni, vedi, VISA - I came, I saw, I bought.
- Raw text -