![]() ![]() | ![]() |
Passage de la branche 4.1 en branche stable.
1: /* 2: ================================================================================ 3: RPL/2 (R) version 4.1.0 4: Copyright (C) 1989-2011 Dr. BERTRAND Joël 5: 6: This file is part of RPL/2. 7: 8: RPL/2 is free software; you can redistribute it and/or modify it 9: under the terms of the CeCILL V2 License as published by the french 10: CEA, CNRS and INRIA. 11: 12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT 13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License 15: for more details. 16: 17: You should have received a copy of the CeCILL License 18: along with RPL/2. If not, write to info@cecill.info. 19: ================================================================================ 20: */ 21: 22: 23: #include "rpl-conv.h" 24: 25: 26: /* 27: ================================================================================ 28: Fonction renvoyant la taille d'un objet en octets 29: (pondérée par le nombre d'occurrences de cet objet) 30: ================================================================================ 31: Entrée : pointeur sur l'objet 32: -------------------------------------------------------------------------------- 33: Sortie : taille 34: -------------------------------------------------------------------------------- 35: Effets de bord : néant 36: ================================================================================ 37: */ 38: 39: integer8 40: occupation_memoire(struct_objet *s_objet) 41: { 42: integer8 longueur; 43: 44: unsigned long i; 45: 46: struct_liste_chainee *l_element_courant; 47: 48: if (s_objet == NULL) 49: { 50: return(0); 51: } 52: 53: switch((*s_objet).type) 54: { 55: case ADR : 56: { 57: longueur = sizeof(unsigned long); 58: break; 59: } 60: 61: case ALG : 62: { 63: l_element_courant = (struct_liste_chainee *) (*s_objet).objet; 64: longueur = 0; 65: 66: while(l_element_courant != NULL) 67: { 68: longueur += occupation_memoire((*l_element_courant).donnee); 69: l_element_courant = (*l_element_courant).suivant; 70: } 71: 72: break; 73: } 74: 75: case BIN : 76: { 77: longueur = sizeof(logical8); 78: break; 79: } 80: 81: case CHN : 82: { 83: longueur = strlen((unsigned char *) (*s_objet).objet) * 84: sizeof(unsigned char); 85: break; 86: } 87: 88: case CPL : 89: { 90: longueur = sizeof(complex16); 91: break; 92: } 93: 94: case FCH : 95: { 96: longueur = sizeof(struct_fonction); 97: longueur += strlen((*((struct_fichier *) (*s_objet).objet)) 98: .nom) * sizeof(unsigned char); 99: longueur += occupation_memoire((*((struct_fichier *) 100: (*s_objet).objet)).format); 101: break; 102: } 103: 104: case FCT : 105: { 106: longueur = sizeof(struct_fonction); 107: longueur += strlen((*((struct_fonction *) (*s_objet).objet)) 108: .nom_fonction) * sizeof(unsigned char); 109: break; 110: } 111: 112: case INT : 113: { 114: longueur = sizeof(integer8); 115: break; 116: } 117: 118: case LST : 119: { 120: l_element_courant = (struct_liste_chainee *) (*s_objet).objet; 121: longueur = 0; 122: 123: while(l_element_courant != NULL) 124: { 125: longueur += occupation_memoire((*l_element_courant).donnee); 126: l_element_courant = (*l_element_courant).suivant; 127: } 128: 129: break; 130: } 131: 132: case MCX : 133: { 134: longueur = sizeof(struct_matrice); 135: longueur += (*((struct_matrice *) (*s_objet).objet)).nombre_lignes * 136: (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes * 137: sizeof(complex16); 138: break; 139: } 140: 141: case MIN : 142: { 143: longueur = sizeof(struct_matrice); 144: longueur += (*((struct_matrice *) (*s_objet).objet)).nombre_lignes * 145: (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes * 146: sizeof(integer8); 147: break; 148: } 149: 150: case MRL : 151: { 152: longueur = sizeof(struct_matrice); 153: longueur += (*((struct_matrice *) (*s_objet).objet)).nombre_lignes * 154: (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes * 155: sizeof(real8); 156: break; 157: } 158: 159: case MTX : 160: { 161: longueur = sizeof(struct_mutex); 162: break; 163: } 164: 165: case NOM : 166: { 167: longueur = strlen((*((struct_nom *) (*s_objet).objet)).nom) * 168: sizeof(unsigned char); 169: break; 170: } 171: 172: case NON : 173: { 174: longueur = 0; 175: break; 176: } 177: 178: case PRC : 179: { 180: longueur = sizeof(struct_processus_fils); 181: break; 182: } 183: 184: case REL : 185: { 186: longueur = sizeof(real8); 187: break; 188: } 189: 190: case RPN : 191: { 192: l_element_courant = (struct_liste_chainee *) (*s_objet).objet; 193: longueur = 0; 194: 195: while(l_element_courant != NULL) 196: { 197: longueur += occupation_memoire((*l_element_courant).donnee); 198: l_element_courant = (*l_element_courant).suivant; 199: } 200: 201: break; 202: } 203: 204: case SCK : 205: { 206: longueur = strlen((*((struct_socket *) (*s_objet).objet)) 207: .adresse) * sizeof(unsigned char); 208: longueur += strlen((*((struct_socket *) (*s_objet).objet)) 209: .adresse_distante) * sizeof(unsigned char); 210: longueur += occupation_memoire((*((struct_fichier *) 211: (*s_objet).objet)).format); 212: break; 213: } 214: 215: case SLB : 216: { 217: longueur = sizeof(struct_bibliotheque); 218: longueur += strlen((*((struct_bibliotheque *) (*s_objet).objet)) 219: .nom) * sizeof(unsigned char); 220: break; 221: } 222: 223: case SPH : 224: { 225: longueur = sizeof(struct_semaphore); 226: longueur += strlen((*((struct_semaphore *) (*s_objet).objet)) 227: .nom) * sizeof(unsigned char); 228: break; 229: } 230: 231: case SQL : 232: { 233: longueur = sizeof(struct_connecteur_sql); 234: longueur += strlen((*((struct_connecteur_sql *) (*s_objet).objet)) 235: .type) * sizeof(unsigned char); 236: longueur += strlen((*((struct_connecteur_sql *) (*s_objet).objet)) 237: .locale) * sizeof(unsigned char); 238: break; 239: } 240: 241: case TBL : 242: { 243: longueur = sizeof(struct_tableau); 244: 245: for(i = 0; i < (*((struct_tableau *) (*s_objet).objet)) 246: .nombre_elements; i++) 247: { 248: longueur += occupation_memoire((*((struct_tableau *) 249: (*s_objet).objet)).elements[i]); 250: } 251: 252: break; 253: } 254: 255: case VCX : 256: { 257: longueur = sizeof(struct_vecteur); 258: longueur += (*((struct_vecteur *) (*s_objet).objet)) 259: .taille * sizeof(complex16); 260: break; 261: } 262: 263: case VIN : 264: { 265: longueur = sizeof(struct_vecteur); 266: longueur += (*((struct_vecteur *) (*s_objet).objet)) 267: .taille * sizeof(integer8); 268: break; 269: } 270: 271: case VRL : 272: { 273: longueur = sizeof(struct_vecteur); 274: longueur += (*((struct_vecteur *) (*s_objet).objet)) 275: .taille * sizeof(real8); 276: break; 277: } 278: 279: default : 280: { 281: longueur = 0; 282: break; 283: } 284: } 285: 286: return(longueur / (*s_objet).nombre_occurrences); 287: } 288: 289: // vim: ts=4