@@ -1191,38 +1191,55 @@ bool Utils::isMemorySufficientForOperation(OperationType operationType, qlonglon
11911191 qlonglong totalMemoryBytes = memoryTotal * DATA_SIZE_1024;
11921192
11931193 // Judge based on operation type
1194- if (operationType == OperationType::CopyOperation ) {
1195- // Copy operation: Estimated memory consumption = data size * factor
1196- qlonglong estimatedMemoryNeeded = operationDataSize * COPY_CONSUME_MEMORY_MULTIPLE;
1197- if (estimatedMemoryNeeded > availableMemoryBytes) {
1198- qWarning () << " Utils: Insufficient memory for copy operation. Needed(est) :" << estimatedMemoryNeeded << " Available:" << availableMemoryBytes;
1199- return false ;
1200- }
1201- } else if (operationType == OperationType::PasteOperation) {
1202- // Paste operation: Estimated memory consumption = paste data size * factor
1203- qlonglong estimatedMemoryNeededForPaste = operationDataSize * PASTE_CONSUME_MEMORY_MULTIPLE;
1204- // Estimated total document memory after paste
1205- qlonglong estimatedTotalDocMemory = (currentDocumentSize + operationDataSize) * PASTE_CONSUME_MEMORY_MULTIPLE; // Estimate using paste factor
1206-
1207- // Check if pasting the data itself would cause insufficient memory
1208- if (estimatedMemoryNeededForPaste > availableMemoryBytes) {
1209- qWarning () << " Utils: Insufficient memory for paste operation (paste data). Needed(est): " << estimatedMemoryNeededForPaste << " Available: " << availableMemoryBytes;
1210- return false ;
1194+ switch (operationType) {
1195+ case OperationType::RawOperation:
1196+ // Raw operation: Directly compare the data size with available memory
1197+ if (operationDataSize > availableMemoryBytes) {
1198+ qWarning () << " Utils: Insufficient memory for raw operation. Needed:" << operationDataSize << " Available:" << availableMemoryBytes;
1199+ return false ;
1200+ }
1201+ break ;
1202+
1203+ case OperationType::CopyOperation: {
1204+ // Copy operation: Estimated memory consumption = data size * factor
1205+ qlonglong estimatedMemoryNeeded = operationDataSize * COPY_CONSUME_MEMORY_MULTIPLE;
1206+ if (estimatedMemoryNeeded > availableMemoryBytes) {
1207+ qWarning () << " Utils: Insufficient memory for copy operation. Needed(est): " << estimatedMemoryNeeded << " Available: " << availableMemoryBytes;
1208+ return false ;
1209+ }
1210+ break ;
12111211 }
1212+
1213+ case OperationType::PasteOperation: {
1214+ // Paste operation: Estimated memory consumption = paste data size * factor
1215+ qlonglong estimatedMemoryNeededForPaste = operationDataSize * PASTE_CONSUME_MEMORY_MULTIPLE;
1216+ // Estimated total document memory after paste
1217+ qlonglong estimatedTotalDocMemory = (currentDocumentSize + operationDataSize) * PASTE_CONSUME_MEMORY_MULTIPLE;
1218+
1219+ // Check if pasting the data itself would cause insufficient memory
1220+ if (estimatedMemoryNeededForPaste > availableMemoryBytes) {
1221+ qWarning () << " Utils: Insufficient memory for paste operation (paste data). Needed(est):" << estimatedMemoryNeededForPaste << " Available:" << availableMemoryBytes;
1222+ return false ;
1223+ }
12121224
1213- // Check if the estimated total document size after paste exceeds total system memory (very rough check)
1214- if (estimatedTotalDocMemory > totalMemoryBytes) {
1215- qWarning () << " Utils: Paste operation might exceed total system memory. Estimated total doc memory:" << estimatedTotalDocMemory << " Total system memory:" << totalMemoryBytes;
1216- return false ;
1217- }
1225+ // Check if the estimated total document size after paste exceeds total system memory
1226+ if (estimatedTotalDocMemory > totalMemoryBytes) {
1227+ qWarning () << " Utils: Paste operation might exceed total system memory. Estimated total doc memory:" << estimatedTotalDocMemory << " Total system memory:" << totalMemoryBytes;
1228+ return false ;
1229+ }
12181230
1219- // Check specific threshold: Restrict paste size if document reaches 800MB
1220- const qlonglong DOC_SIZE_LIMIT_800MB = 800LL * DATA_SIZE_1024 * DATA_SIZE_1024;
1221- const qlonglong PASTE_SIZE_LIMIT_500KB = 500LL * DATA_SIZE_1024;
1222- if (currentDocumentSize > DOC_SIZE_LIMIT_800MB && operationDataSize > PASTE_SIZE_LIMIT_500KB) {
1223- qWarning () << " Utils: Paste operation restricted. Document size exceeds 800MB and paste data exceeds 500KB." ;
1224- return false ;
1231+ // Check specific threshold: Restrict paste size if document reaches 800MB
1232+ const qlonglong DOC_SIZE_LIMIT_800MB = 800LL * DATA_SIZE_1024 * DATA_SIZE_1024;
1233+ const qlonglong PASTE_SIZE_LIMIT_500KB = 500LL * DATA_SIZE_1024;
1234+ if (currentDocumentSize > DOC_SIZE_LIMIT_800MB && operationDataSize > PASTE_SIZE_LIMIT_500KB) {
1235+ qWarning () << " Utils: Paste operation restricted. Document size exceeds 800MB and paste data exceeds 500KB." ;
1236+ return false ;
1237+ }
1238+ break ;
12251239 }
1240+
1241+ default :
1242+ break ;
12261243 }
12271244
12281245 return true ; // Memory is sufficient
0 commit comments