Home Segments Index Top Previous Next

450: Mainline

There is a way to wiggle out of C's prohibition of mixed objects, however. You can tell the C compiler to allocate memory chunks for array elements such that each chunk is large enough for the larger of bond_trade objects and stock_trade objects:

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
| | | | | | | | | | | | | | | | |          <-- 16 bytes required for 
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              stock_trade objects 
 --------------- ------- ------- 
        ^           ^       ^     
        |           |       *-- pe_ratio 
      price      number 
         |          |          *-- yield 
         v          v          v 
 --------------- ------- --------------- 
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
| | | | | | | | | | | | | | | | | | | | |  <-- 20 bytes required for 
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*      bond_trade objects 

If you happen to put a stock_trade object in such a chunk, 4 bytes are left unused.