Salve,
ho questa struttura:
E dovrei calcolarne la dimensione in byte degli elementi effettivamente presenti all'interno della struttura poichè, in base al resto del codice, i vettori all'interno della struttura non vengono necessariamente riempiti tutti.codice:struct stringpool { int identifiers[100]; char strings[100][100]; int foundPos; enum error {SUCCESS,KO_DUPLICATE_FOUND,KO_NULL_STRING, KO_FULL_POOL,ID_NOT_VALID,ID_NOT_FOUND,KO_DUPLICATE_FILE, KO_NO_DATA,KO_FILE_NOT_EXIST}; }sp;
Quindi ho fatto così:
Così ho la dimensione degli elementi in identifiers e strings, è corretto?codice:for (i = 0; i < dim_str; i++){ if (sp.identifiers[i] != -1){ l = l + 1; } } size_ide = sizeof (int) * l; for (i = 0; i < dim_str; i++){ for (j = 0; j < dim_str; j++){ if (sp.strings[i][j] != NULL){ n = n + 1; } } } size_str = sizeof (char) * n;
Poi visto che in sp ci sono anche altri elementi che dovrei conteggiare mi basterebbe sommare i seguenti:
a size_str e size_ide o non è corretto?codice:sizeof(sp.foundPos) sizeof(enum error)
Mi è sorto il dubbio perchè la dimensione di foundPos mi risulta 4 e quella di enum error anche. Però in totale sp è 10404 con 10000 per i char e 400 per int, qunindi non mi trovo con i conti e credo che sbaglio qualcosa...
che ne dite?
Grazie a tutti in anticipo.

,
Rispondi quotando
