Возникла проблема при вызове ReadDirectoryChangesW — после занесения определенного количества событий в массив — события перестают отлавливатся. При динамическом выделении памяти — память занятая под массив не освобождается.
FILE_NOTIFY_INFORMATION *fn = new FILE_NOTIFY_INFORMATION[file_cnt];
DWORD buff_size = sizeof(FILE_NOTIFY_INFORMATION)*file_cnt;
int cnt = 0;
DWORD lpBytesReturned;
while(true){
while(ReadDirectoryChangesW(
hDir, //handle to the monitoring directory
fn, //structure to satisfy the FILE_NOTIFY_INFORMATION buffer
buff_size, //size of BUFFER
TRUE, //include subdirectories
FILE_NOTIFY_CHANGE_FILE_NAME|
FILE_NOTIFY_CHANGE_DIR_NAME|
FILE_NOTIFY_CHANGE_ATTRIBUTES|
FILE_NOTIFY_CHANGE_SIZE|
FILE_NOTIFY_CHANGE_LAST_WRITE|
FILE_NOTIFY_CHANGE_LAST_ACCESS|
FILE_NOTIFY_CHANGE_CREATION|
FILE_NOTIFY_CHANGE_SECURITY,
&lpBytesReturned,
NULL,
NULL))
{
cnt++;
switch(fn[0].Action){
case FILE_ACTION_ADDED:
break; //The file was added to the directory.
case FILE_ACTION_REMOVED:
break;//The file was removed from the directory.
case FILE_ACTION_MODIFIED:
break;//The file was modified. This can be a change in the time stamp or attributes.
case FILE_ACTION_RENAMED_OLD_NAME:
break;//The file was renamed and this is the old name.
case FILE_ACTION_RENAMED_NEW_NAME:
break;
}//switch of the Actions
if (cnt==file_cnt){
delete [] fn;
cnt=0;
fn = new FILE_NOTIFY_INFORMATION[file_cnt];
}
Здравствуйте, sunrizer, Вы писали:
S>Возникла проблема при вызове ReadDirectoryChangesW — после занесения определенного количества событий в массив — события перестают отлавливатся. При динамическом выделении памяти — память занятая под массив не освобождается.
S> FILE_NOTIFY_INFORMATION *fn = new FILE_NOTIFY_INFORMATION[file_cnt];
Вот это вообще ИМХО неверно. См. формат
The FILE_NOTIFY_INFORMATION structure describes the changes found by the ReadDirectoryChangesW function.
NextEntryOffset
Number of bytes that must be skipped to get to the next record. A value of zero indicates that this is the last record.
Иными словами, там не массив. Там линейный список, которым не ты управляешь. Заказать можно буфер любого размера, но
Upon successful synchronous completion, the lpBuffer parameter is a formatted buffer and the number of bytes written to the buffer is available in lpBytesReturned. If the number of bytes transferred is zero (0), the buffer was too small to provide detailed information on all the changes that occurred in the directory or subtree. In this case, you should compute the changes by enumerating the directory or subtree.