For Windows users, if you try searching the MySQL source code for various strings, you know you will often come up empty with the built-in Windows search.
It wasn’t too long ago and I was searching the source for “MALLOC_OVERHEAD”. My Windows search came up empty, and someone suggested I try grep for Windows.
Well, I downloaded it, extracted it to the location I wanted, and added the .exe to the $PATH.
Now I can grep away!
See the new results when searching for “MALLOC_OVERHEAD”:
C:\mysql-5.5\mysql-5.5>grep -r "MALLOC_OVERHEAD" . ./client/mysql.cc: (longlong) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, ./client/mysql.cc: REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0}, ./client/mysqldump.c: (longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, ./client/mysqldump.c: MALLOC_OVERHEAD-1024, 1024, 0}, ./client/mysqltest.cc: my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/ ./client/mysqltest.cc: if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD), ./client/mysqltest.cc: pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+ ./client/mysqltest.cc: pa->max_length=PS_MALLOC-MALLOC_OVERHEAD; ./client/mysqltest.cc: len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD); ./extra/replace.c: my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/ ./extra/replace.c: if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD), ./extra/replace.c: pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+ ./extra/replace.c: pa->max_length=PS_MALLOC-MALLOC_OVERHEAD; ./extra/replace.c: pa->max_length=(pa->length+length+MALLOC_OVERHEAD+PS_MALLOC-1)/PS_MALLOC; ./extra/replace.c: pa->max_length=pa->max_length*PS_MALLOC-MALLOC_OVERHEAD; ./extra/replace.c: len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD); ./include/my_global.h: something like 1024-MALLOC_OVERHEAD bytes ./include/my_global.h:#define MALLOC_OVERHEAD 8 ./include/my_global.h:#define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD) ./include/my_global.h:#define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD) ./include/my_sys.h:#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8 ) Binary file ./MySQL.ncb matches ./mysys/array.c: alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16); ./storage/myisam/ha_myisam.cc: 8192*1024, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), ULONG_MAX, 1); ./storage/myisam/myisamchk.c: GET_ULL, REQUIRED_ARG, USE_BUFFER_INIT, MALLOC_OVERHEAD, ./storage/myisam/myisamchk.c: SIZE_T_MAX, MALLOC_OVERHEAD, IO_SIZE, 0}, ./storage/myisam/myisamchk.c: (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD, ./storage/myisam/myisamchk.c: INT_MAX32, (long) MALLOC_OVERHEAD, (long) 1L, 0}, ./storage/myisam/myisamchk.c: (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD, ./storage/myisam/myisamchk.c: INT_MAX32, (long) MALLOC_OVERHEAD, (long) 1L, 0}, ./storage/myisam/myisamchk.c: (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), ./storage/myisam/myisamchk.c: ULONG_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0}, ./storage/myisam/myisamdef.h:#define USE_BUFFER_INIT (((1024L*512L-MALLOC_OVERHEAD)/IO_SIZE)*IO_SIZE) ./storage/myisam/myisamdef.h:#define READ_BUFFER_INIT (1024L*256L-MALLOC_OVERHEAD) ./storage/myisam/myisamdef.h:#define SORT_BUFFER_INIT (2048L*1024L-MALLOC_OVERHEAD) ./storage/myisam/myisamdef.h:#define MIN_SORT_BUFFER (4096-MALLOC_OVERHEAD) ./storage/myisam/myisampack.c:static uint tree_buff_length= 65536 - MALLOC_OVERHEAD;
Unlike the Windows search, which simply returns the file name, this shows the file name *and* the full line of code, therefore sometimes answering my question without even needing to examine the source code.
This full search of the source code (which I had stored in C:\mysql-5.5\mysql-5.5) took only about 2 minutes. This is not bad (and certainly not worse than the Windows search), not to mention there’s no need to index your system, nor build/store the resulting several-GB-search-index-file, aka windows.edb).
Personally, I use the ‘GnuWin32′ grep for Windows, available from SourceForge:
http://gnuwin32.sourceforge.net/packages/grep.htm
I’m sure there are others, but I’ve had great success using many of the GnuWin32 utilities available for Windows.
Happy grepping!
PlanetMySQL Voting: Vote UP / Vote DOWN