[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freetds
Subject:    Re: [freetds] tds_get_string
From:       "James K. Lowden" <jklowden () schemamania ! org>
Date:       2003-03-31 11:39:20
[Download RAW message or body]

On 30 Mar 2003 21:43:22 +0200, Frediano Ziglio <freddyz77@tin.it> wrote:
> Il dom, 2003-03-30 alle 21:32, James K. Lowden ha scritto:
> > read.c::tds_get_string() contains what looks like a silly loop:
> > 
> > 	char temp[256];
> > 	char *p, *pend;
> > 	/* ... */
> > 	while (string_len > 0 && p < pend) {
> > 		in_left = string_len > (sizeof(temp) / 2) ? 
> > 			(sizeof(temp) / 2) : string_len;
> > 		tds_get_n(tds, temp, in_left * 2);
> > 		p += tds7_unicode2ascii(tds, temp, in_left, p, pend - p);
> > 		string_len -= in_left;
> > 	}
> > 	return p - dest;
> > 
> > Basically, if the input string is more than 128 characters, we call
> > tds_get_n() and tds7_unicode2ascii() in 128-character chunks.  
> > 
> > Why do we do this?  I can't see any reason.  
> 
> Cause you don't use malloc?
> tds_get_string can't return a "I'm sorry but your computer is out of
> memory" results, so avoiding malloc fix the problem.

Thanks, I see.  I think I misread the logic.  temp is the
"preconversion" buffer, the place where the UCS-2 data are parked
before converting them to ASCII.  It has to have a size, and there's
no advantage to allocating dynamically.  

--jkl
_______________________________________________
FreeTDS mailing list
FreeTDS@lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic