libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

objectSizeof.c (3463B)


      1 //
      2 
      3 #include "../release/libsheepyObject.h"
      4 
      5 #define internal static
      6 
      7 #include <stdlib.h>
      8 #include <stdbool.h>
      9 #include <string.h>
     10 #include <stdio.h>
     11 
     12 #ifndef unitTest
     13 #endif
     14 int MAIN(int ARGC, char** ARGV);
     15 
     16 int argc; char **argv;
     17 
     18 #ifndef unitTest
     19 // Remove main when running the unit tests
     20 #define MAIN   main
     21 #endif
     22 int MAIN(int ARGC, char** ARGV) {
     23   char *S = NULL;
     24 
     25   argc = ARGC; argv = ARGV;;// printf("%s\n", sizeof of small objects and s objects);
     26   // and how the array and the dictionary grow as elements are added.
     27 
     28   puts(BLD GRN "SIZEOF" RST);
     29   puts(GRN "sBoolt is the data stucture representing bool in smallBoolt, smallArrayt and smallDictt" RST);
     30   puts(GRN "same for other sObjects" RST); {
     31 
     32   printf("Object      smallBoolt sizeof: %d", sizeof(smallBoolt));
     33   printf("\n");
     34   sBoolt *b;
     35   b = allocSBool(false);
     36   printf("                sBoolt sizeof: %d", sizeof(sBoolt));
     37   printf("\n");
     38   S = sToStringTiny((smallt *) b);
     39   logNFree(S);
     40   free(b);
     41   put
     42 
     43   printf("Object smallContainert sizeof: %d", sizeof(smallContainert));
     44   printf("\n");
     45   sContainert *c;
     46   c = allocSContainer(strdup("sheepy"));
     47   printf("           sContainert sizeof: %d (+sizeof data)", sizeof(sContainert));
     48   printf("\n");
     49   S = sToStringTiny((smallt *) c);
     50   logNFree(S);
     51   free(c->data);
     52   free(c);
     53   put
     54 
     55   printf("Object      smallDictt sizeof: %d", sizeof(smallDictt));
     56   printf("\n");
     57   sDictt *d;
     58   d = allocSDict();
     59   printf("                sDictt sizeof: %d (+ (count-1) * sizeof sDictElemt)", sizeof(sDictt));
     60   printf("\n");
     61   printf("            sDictElemt sizeof: %d", sizeof(sDictElemt));
     62   printf("\n");
     63   S = sToStringTiny((smallt *) d);
     64   logNFree(S);
     65   free(d);
     66   put
     67 
     68   printf("Object    smallDoublet sizeof: %d", sizeof(smallDoublet));
     69   printf("\n");
     70   sDoublet *D;
     71   D = allocSDouble(10);
     72   printf("              sDoublet sizeof: %d", sizeof(sDoublet));
     73   printf("\n");
     74   S = sToStringTiny((smallt *) D);
     75   logNFree(S);
     76   free(D);
     77   put
     78 
     79   printf("Object       smallIntt sizeof: %d", sizeof(smallIntt));
     80   printf("\n");
     81   sIntt *i;
     82   i = allocSInt(10);
     83   printf("                 sIntt sizeof: %d", sizeof(sIntt));
     84   printf("\n");
     85   S = sToStringTiny((smallt *) i);
     86   logNFree(S);
     87   free(i);
     88   put
     89 
     90   printf("Object    smallStringt sizeof: %d", sizeof(smallStringt));
     91   printf("\n");
     92   sStringt *s;
     93   s = allocSStringTiny("qweqwe");
     94   printf("              sStringt sizeof: %d", sizeof(sStringt));
     95   printf("\n");
     96   S = sToStringTiny((smallt *) s);
     97   logNFree(S);
     98   free(s);
     99   put
    100 
    101   printf("Object     smallArrayt sizeof: %d", sizeof(smallArrayt));
    102   printf("\n");
    103   sArrayt *a;
    104   a = allocSArray();
    105   printf("               sArrayt sizeof: %d (+ (count-1) * sizeof *ptr)", sizeof(sArrayt));
    106   printf("\n");
    107   S = sToStringTiny((smallt *) a);
    108   logNFree(S);
    109   free(a);
    110   put
    111 
    112   printf("Object      undefinedt sizeof: %d", sizeof(undefinedt));
    113   printf("\n");
    114   sUndefinedt *u;
    115   u = allocSUndefined();
    116   printf("           sUndefinedt sizeof: %d", sizeof(sUndefinedt));
    117   printf("\n");
    118   S = sToStringTiny((smallt *) u);
    119   logNFree(S);
    120   free(u);
    121   put
    122 
    123   printf("Object     smallBytest sizeof: %d", sizeof(smallBytest));
    124   printf("\n");
    125   sBytest *B;
    126   B = allocSBytes();
    127   sBytesPush(&B, 1);
    128   sBytesPush(&B, 2);
    129   sBytesPush(&B, 3);
    130   printf("               sBytest sizeof: %d (+ (count-1) * sizeof char)", sizeof(sBytest));
    131   printf("\n");
    132   S = sToStringTiny((smallt *) B);
    133   logNFree(S);
    134   free(B);
    135 
    136   finalizeLibsheepy();
    137 }
    138   }