使用WinPCap項目。試圖做一些基本的指針和內存操作,並有很多錯誤。奇數內存錯誤 - 錯誤Alloc
我已經包含了兩條線,我試圖與包含一起運行。 另一個VSC++項目中的相同行很好。這是我得到
錯誤在 pktdump_ex.exe在0x75a79617未處理的異常:微軟C++ 例外:性病:: bad_alloc的內存在位置 .. 0x0012f8e4
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include "DataTypes.h"
#include <sstream>
#include "EthernetLayer.h"
#include <pcap.h>
int* testPointer = new int[2];
delete[] testPointer;
編輯: 找到一些有用的東西。 以下代碼片段是造成winpcap庫崩潰的原因。
EthernetStructPointers* testData;
testData = (EthernetStructPointers*)pkt_data;
EthernetStruct newData;
memcpy(newData.DEST_ADDRESS, testData->DEST_ADDRESS, 6);
這些是結構的定義。當您嘗試new
的東西,已經耗盡內存
struct EthernetStructPointers
{
u_char DEST_ADDRESS[6];
u_char SOURCE_ADDRESS[6];
u_char TYPE[2];
};
struct EthernetStruct
{
u_char DEST_ADDRESS[6];
u_char SOURCE_ADDRESS[6];
u_char TYPE[2];
u_char* dataPointer;
string DestAddress;
string SourceAddress;
string Type;
int length;
};
這兩行很好,這就是爲什麼他們在其他程序中工作。無論您的問題是什麼,您都已將其從帖子中刪除。我會建議製作最小可能的完整播放器併發布它。 – 2010-01-16 20:48:31
我沒有看到你使用'new []'和'delete []'有什麼問題。難道這些運營商在全球被覆蓋幷包含一些不好的代碼? – stakx 2010-01-16 20:52:24
我會嘗試發佈代碼,但它需要WinPCap可用。 – bobber205 2010-01-16 20:53:32