Templates and object size in C-Set C++

Templates and object size in C-Set C++

Post by Stephen Lew » Tue, 07 Feb 1995 18:23:48

Just wondering if anybody else has noticed the huge increase in object size
when using the collection class templates under IBM C-Set C++.  With a
simple class definition and a list definition using ISet the object file
size was 12682 bytes.  In contrast, the size without the use of ISet was
804 bytes.

Does anybody know the reason for this?  This is quite worrying as we are
using the collection classes a lot in our code and have noticed that,
with debugging information, some of our object files are close to half
a megabyte in size.

We are setting the templates used option in the ICC linker, but other
than that everything is standard.

Is there something I'm missing.



            Stephen Lewis                | fax: +431 29 21 452    \~~~~\0~~~\
   Design Engineer, Voice Processing     | voice: +431 29 121 157  \~~c=|=-~~\
   Alcatel Austria AG, Ruthnergasse 1-7, |                         ))))) \ )))
         A-1210 Vienna, Austria          | Kayaking on the edge.  ///~////////


Templates and object size in C-Set C++

Post by PeterKob » Sun, 12 Feb 1995 04:13:07

Quote:> Just wondering if anybody else has noticed the huge increase in object
> when using the collection class templates under IBM C-Set C++.

Yes, I was rather disappointed. We're a C shop and I sold management the
idea of going to C++ for new development mainly for use of the class
libraries. I hadn't tried them before recently. With debugging on and
using dynamic linked libraries, one executable went from 13k to 111k; like
you, using just one ISet template. Maybe the linker isn't smart enough? I
hope somebody has some magic to make these smaller.


1. Problem with templates in C-Set++

I'm having a problem with using template classes and the C-Set++
compiler.  I can't seem to get the compiler to instantiate the member
functions properly unless the functions are inline.

I'll enclose some sample code at the end.  Anyway, in the case of the
example code, both of the member functions, the constructor and the []
operator, aren't being instantiated for Vector<int>.

Originally, I had the member functions in a completely separate file
(the functions were defined in Vector.cxx and the class was defined in
Vector.h), but at someone's suggestion, I included the .cxx file in
the main code as well.  This didn't help, either.

If someone could explain to me what I'm doing wrong, I'd appreciate
it.  (NOTE: this code works just fine with the SunPro C++ compiler)

Here's the code (in shar format):

echo "Extracting Vector.cxx"
cat <<VECTOR_CXX >Vector.cxx
#include "Vector.h"

template <class T> Vector<T>::Vector()
  size = 10;  data = new T[size];

template <class T> T& Vector<T>::operator[](int n)
  int os;
  int i;
  T* newdata;

  if (n >= size) {
    os = size;
    while (size <= n) size *= 2;
    newdata = new T[size];
    for (i = 0; i < os; i++) newdata[i] = data[i];
    delete data;
    data = newdata;
  return data[n];
echo "Extracting Vector.h"
cat <<VECTOR_H >Vector.h
#ifndef VECTOR_H
#define VECTOR_H

template <class T> class Vector {
  T* data;
  int size;
  T& operator[](int);

echo "Extracting vtest.cxx"
cat <<VTEST_CXX >vtest.cxx
#include <iostream.h>
#include "Vector.h"
#include "Vector.cxx"

  Vector<int> v;
  int i;

  for (i = 1; i <= 15; i++)
    v[i] = i * i;

  for (i = 1; i <= 15; i++)
    cout << i << " " << v[i] << "\n";
John Knutson

"This must be the place I've waited years to leave" --Pet Shop Boys

2. Data Access Block and the GAC

3. Help - Deleting Template Object C/Set

4. VC++

5. Template with ICC??? (Using IBM C++ Set/2)

6. Money 2K Upgrade Without Outlook Express 5.0?

7. New C-Set++?

8. How to customize page breaking inside a paragraph

9. **** Compiling Problems with C-Set v2.1

10. IBM C-Set/2 1.0

11. C-Set++ Profiles under Merlin

12. Q: WATCOM-DLL called by C-Set/2 - Executable

13. Help destroying file handles in ibm C-Set