On Jan 18 21:57, Takashi Yano via Cygwin-patches wrote: > On Mon, 18 Jan 2021 13:39:01 +0100 > Corinna Vinschen wrote: > > Sorry if I'm slow, but I was just mulling over this code snippet again, > > and I was wondering if we couldn't do without the HeapAlloc loop. > > Assuming you use a tmp_pathbuf here, you'd have space for 16384 > > processes per console. Shouldn't that be more than enough? I.e. > > > > static DWORD > > get_console_process_id (DWORD pid, bool match) > > { > > tmp_pathbuf tp; > > DWORD *list = (DWORD *) tp.w_get (); > > const DWORD num = NT_MAX_PATH * sizeof (WCHAR) / sizeof (DWORD); > > DWORD res = 0; > > > > num = GetConsoleProcessList (&list, num); > > > > /* Last one is the oldest. */ > > /* https://github.com/microsoft/terminal/issues/95 */ > > for (int i = (int) num - 1; i >= 0; i--) > > if ((match && list[i] == pid) || (!match && list[i] != pid)) > > { > > res = list[i]; > > break; > > } > > return res; > > } > > > > > > What do you think? > > That's more that enough. I will submit v3 patch. Thanks again. > By the way, why do you think tmp_pathbuf is better than HeapAlloc()?
tmp_pathbuf never frees the buffers it used at least once. so chances are hight that the call just returns the next free pointer to an already alloocated buffer. Corinna