> > So then I think your point, translated to implementation requirements, > would be to: > > 1) Use a 256 byte buffer for -multisel => 0 (why waste memory) > 2) Use a 4000 byte buffer for -multisel => 1 (allow more files to be > selected normally, even if the user hasn't caught on to doing memory > management) > 3) For simplicity, and smaller numbers, one could just multiply > -multisel by 4000 with a minimum of 256 bytes for the zero case, and > achieve all these goals. And a 4000 byte granularity on allocation of > the buffer is probably not a big deal for people that need big buffers. > > I've made these adjustments. I'll hold off committing them until next > week, in case there are other comments. >
I think it's not a problem to upgrade default stack buffer to 4096 by default. Stack allocation is generally same speed for 256 and 4096. And only dynamicly allocate a buffer when desired size isn't enough. Something like that : void GetOpenFileName(...) PPCODE: ... char filename[4096]; ... filename[0] = '\0'; ofn.lpstrFile = filename; ofn.nMaxFile = 4096; ... } else if(strcmp(option, "-multisel") == 0) { next_i = i + 1; SwitchBit(ofn.Flags, OFN_ALLOWMULTISELECT, SvIV(ST(next_i))); if ( ofn.nMaxFile < (MAX_PATH * SvIV(ST(next_i))) ) { ofn.nMaxFile = MAX_PATH * SvIV(ST(next_i)); ofn.lpstrFile = (char *) safemalloc(ofn.nMaxFile); ofn.lpstrFile[0] = '\0'; } } ... if(retval) { if (ofn.Flags & OFN_ALLOWMULTISELECT) { ... if (ofn.lpstrFile != filename) safefree(ofn.lpstrFile); XSRETURN(i); ... Laurent.