On Sun, Jul 26, 2009 at 6:16 PM, Matt Ingenthron<mingenth...@acm.org> wrote: > >> If not, then something like this should work: >> >> this->foo = (char *)alloca(arg2 + 1); >> copyinto(arg1, arg2, this->foo); >> this->foo[arg2 + 1] = '\0'; >> printf("%s\n", stringof(this->foo)); > > > Makes sense. Is there significant overhead for doing that alloca() every > time though? Is there any benefit in doing it global or thread-local? In my > use case, there will only be one 'command' probe firing for each thread at > any given time, so I think I could do the alloca() at command start and zero > it out at command end with a thread local. I don't know if there are any > DTrace overhead benefits for this, but it may make for a more readable script. >
There's actually no real difference performance-wise between the above and the following: this->foo = (char *)copyin(arg1, arg2); this->foo[arg2 + 1] = '\0'; printf("%s\n", stringof(this->foo)); Both the copyin() and the alloca() allocate space out of scratch space, and in fact, they share the same code path to do so. The only performance penalty being paid here is in doing this as two separate subroutine calls rather than a single one. The alloca() is safer, though, because it covers that edge case where the copyin() would use the remaining scratch space, making this->foo[arg2 + 1] an illegal address. Also, the space allocated by alloca() is only valid within that clause, so it has to be clause-local. Chad _______________________________________________ dtrace-discuss mailing list dtrace-discuss@opensolaris.org