Objects in memory
CFRuntimeClass
Gli oggetti CF* provengono da CoreFoundation, che fornisce più di 50 classi di oggetti come CFString
, CFNumber
o CFAllocatior
.
Tutte queste classi sono istanze della classe CFRuntimeClass
, che quando chiamata restituisce un indice alla __CFRuntimeClassTable
. Il CFRuntimeClass è definito in CFRuntime.h:
Objective-C
Sezioni di memoria utilizzate
La maggior parte dei dati utilizzati dall'esecuzione di ObjectiveC cambierà durante l'esecuzione, quindi utilizza alcune sezioni del segmento __DATA in memoria:
__objc_msgrefs
(message_ref_t
): Riferimenti ai messaggi__objc_ivar
(ivar
): Variabili di istanza__objc_data
(...
): Dati mutabili__objc_classrefs
(Class
): Riferimenti alle classi__objc_superrefs
(Class
): Riferimenti alle superclassi__objc_protorefs
(protocol_t *
): Riferimenti ai protocolli__objc_selrefs
(SEL
): Riferimenti ai selettori__objc_const
(...
): Dati della classer/o
e altri dati (sperabilmente) costanti__objc_imageinfo
(versione, flag
): Utilizzato durante il caricamento dell'immagine: Versione attualmente0
; I flag specificano il supporto preottimizzato per il GC, ecc.__objc_protolist
(protocol_t *
): Elenco dei protocolli__objc_nlcatlist
(category_t
): Puntatore alle categorie Non-Lazy definite in questo binario__objc_catlist
(category_t
): Puntatore alle categorie definite in questo binario__objc_nlclslist
(classref_t
): Puntatore alle classi Objective-C Non-Lazy definite in questo binario__objc_classlist
(classref_t
): Puntatori a tutte le classi Objective-C definite in questo binario
Utilizza anche alcune sezioni nel segmento __TEXT
per memorizzare valori costanti se non è possibile scriverli in questa sezione:
__objc_methname
(Stringa-C): Nomi dei metodi__objc_classname
(Stringa-C): Nomi delle classi__objc_methtype
(Stringa-C): Tipi di metodi
Codifica dei tipi
Objective-C utilizza alcune manipolazioni per codificare i tipi di selettori e variabili di tipi semplici e complessi:
I tipi primitivi utilizzano la loro prima lettera del tipo
i
perint
,c
perchar
,l
perlong
... e utilizzano la lettera maiuscola nel caso in cui sia senza segno (L
perunsigned Long
).Altri tipi di dati le cui lettere sono utilizzate o sono speciali, utilizzano altre lettere o simboli come
q
perlong long
,b
percampi di bit
,B
perbooleani
,#
perclassi
,@
perid
,*
perpuntatori a char
,^
perpuntatori generici
e?
pernon definito
.Gli array, le strutture e le unioni utilizzano
[
,{
e(
Esempio di Dichiarazione del Metodo
Il selettore sarebbe processString:withOptions:andError:
Codifica del Tipo
id
è codificato come@
char *
è codificato come*
La codifica completa del tipo per il metodo è:
Scomposizione Dettagliata
Tipo di Ritorno (
NSString *
): Codificato come@
con lunghezza 24self
(istanza dell'oggetto): Codificato come@
, all'offset 0_cmd
(selettore): Codificato come:
, all'offset 8Primo argomento (
char * input
): Codificato come*
, all'offset 16Secondo argomento (
NSDictionary * options
): Codificato come@
, all'offset 20Terzo argomento (
NSError ** error
): Codificato come^@
, all'offset 24
Con il selettore + la codifica è possibile ricostruire il metodo.
Classi
Le classi in Objective-C sono una struttura con proprietà, puntatori a metodi... È possibile trovare la struttura objc_class
nel codice sorgente:
Questo classe utilizza alcuni bit del campo isa per indicare alcune informazioni sulla classe.
Successivamente, la struct ha un puntatore alla struct class_ro_t
memorizzata su disco che contiene attributi della classe come il suo nome, metodi di base, proprietà e variabili di istanza.
Durante l'esecuzione, una struttura aggiuntiva class_rw_t
viene utilizzata contenente puntatori che possono essere modificati come metodi, protocolli, proprietà...
Last updated