The R Project SVN R

Rev

Rev 12976 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12976 Rev 27656
Line 33... Line 33...
33
   2) an object gets charged for all the space allocated on the heap
33
   2) an object gets charged for all the space allocated on the heap
34
      and all the nodes specifically due to it, but not for the 
34
      and all the nodes specifically due to it, but not for the 
35
      space for its name nor for builtins it references
35
      space for its name nor for builtins it references
36
*/
36
*/
37
 
37
 
38
static int objectsize(SEXP s)
38
static unsigned long objectsize(SEXP s)
39
{
39
{
-
 
40
    int i;
40
    int i, cnt = 0, vcnt = 0;
41
    unsigned long cnt = 0, vcnt = 0;
41
    
42
    
42
    switch (TYPEOF(s)) {
43
    switch (TYPEOF(s)) {
43
    case NILSXP:
44
    case NILSXP:
44
	return(0);
45
	return(0);
45
	break;
46
	break;
Line 89... Line 90...
89
	vcnt = PTR2VEC(length(s));
90
	vcnt = PTR2VEC(length(s));
90
	for (i = 0; i < length(s); i++)
91
	for (i = 0; i < length(s); i++)
91
	    cnt += objectsize(VECTOR_ELT(s, i));
92
	    cnt += objectsize(VECTOR_ELT(s, i));
92
	break;
93
	break;
93
    default:
94
    default:
94
	error("object.size: unknown type %i", TYPEOF(s));
95
	error("object.size: unknown type %d", TYPEOF(s));
95
    }
96
    }
96
    cnt += 8 * vcnt;
97
    cnt += 8 * vcnt;
97
    /* add in node space */
98
    /* add in node space */
98
    cnt += sizeof(SEXPREC);
99
    cnt += sizeof(SEXPREC);
99
    /* add in attributes */
100
    /* add in attributes */
Line 103... Line 104...
103
 
104
 
104
 
105
 
105
SEXP do_objectsize(SEXP call, SEXP op, SEXP args, SEXP env)
106
SEXP do_objectsize(SEXP call, SEXP op, SEXP args, SEXP env)
106
{
107
{
107
    SEXP ans;
108
    SEXP ans;
108
    int cnt = 0;
109
    unsigned long cnt = 0;
109
    
110
    
110
    checkArity(op, args);
111
    checkArity(op, args);
111
    cnt = objectsize(CAR(args));
112
    cnt = objectsize(CAR(args));
112
    PROTECT(ans = allocVector(INTSXP, 1));
113
    PROTECT(ans = allocVector(REALSXP, 1));
113
    INTEGER(ans)[0] = cnt;
114
    REAL(ans)[0] = cnt;
114
    UNPROTECT(1);
115
    UNPROTECT(1);
115
    return ans;
116
    return ans;
116
}
117
}