内存不足 - C解释器错误 - 想法?

时间:2015-08-06 14:40:16

标签: c memory-management memory-leaks out-of-memory loadrunner

所以我遇到了解决C解释器错误的问题 - 在大多数负载生成器上运行脚本时出现内存冲突。我们有一些服务器2003(8gb ram)负载生成器,脚本运行正常。但是所有的Windows 7机器(4gb ram)都不会运行脚本。我的第一个倾向是它刚刚耗尽内存,但是当我在运行它时运行它时在2003服务器上观察资源时,它只增加了200mb的内存。

脚本的作用:它将文件读入内存,然后将该缓冲区分配给LR参数,然后将该参数分配给MTOM SOAP请求的附件。当使用20mb及以下的小文件时,我可以在VUgen中运行它,更大的文件,如85mb,我得到内存访问冲突。然后我必须使用2003服务器负载生成器在性能中心运行它,它运行并执行正常。

由于它在具有更多内存的机器上运行,我认为这更多是由于内存可用,但是当脚本运行时,在2003服务器LG上使用的并不多。

对此的任何见解都会很棒!

代码:

#define SEEK_SET 0 /* beginning of file. */
#define SEEK_CUR 1 /* current position. */
#define SEEK_END 2   /* end of file */

int requestPrepared = 0;
 char *filename2 = "test.gz";

setEXTERNALfile()
{
 long infile; // file pointer
 char *buffer; // buffer to read file contents into
 //Old Code
 //char *filename = "C:\\EPD\\INDIVIDUAL\\XML\\EPDIndividual_1.xml"; // file to read. old code.
 //Old code
 char *filenumber[15];
 int fileLen; // file size
 int newfileLen; // New file size
 int fileSizeSub; //linix file si
 int bytesRead; // bytes read from file

 char newfilename[40]; //contains file name path
 char *fileext = ".xml"; // ext of file to read

 typedef void *gzFile;
 gzFile file;

  int count;

 //char *filenumber2[40];
 char filename[155];
 char fileDirectory[155];

 sprintf(fileDirectory, "%s", lr_eval_string("{pFileDirectory}"));
 lr_output_message("Current fileDirectory %s", lr_eval_string("{pFileDirectory}"));

 sprintf(filename, "%s", lr_eval_string("{pFileName}"));

//  80 MB file
 sprintf(newfilename,"\\\\LOCATION\\%s\\%s%s", fileDirectory, filename, fileext);

 // open the file
 infile = fopen(newfilename, "rb");
 if (!infile) {
   lr_error_message("Unable to open file %s", newfilename);
   return;
 }


 // get the file length
 fseek(infile, 0, SEEK_END);
 fileLen=ftell(infile);
 newfileLen=ftell(infile)+2;
 fseek(infile, 0, SEEK_SET);
 lr_log_message("File length is: %9d bytes.", fileLen);
 lr_save_int(newfileLen,"pNewFileSize");
 lr_log_message("New File length is: %9d bytes.", newfileLen);


 // Allocate memory for buffer to read file
 buffer=(char *)malloc(fileLen+1);
 if (!buffer) {
   lr_error_message("Could not malloc %10d bytes", fileLen+1);
   fclose(infile);
   return;
 }


 // Read file contents into buffer
 bytesRead = fread(buffer, 1, fileLen, infile);
 if (bytesRead != fileLen) 
 {
   lr_error_message("File length is %10d bytes but only read %10d bytes", fileLen, bytesRead);
 }
 else
 {
   lr_log_message("Successfully read %9d bytes from file: ", bytesRead);
 }
 fclose(infile);


 // Save the buffer to a loadrunner parameter
 lr_save_var( buffer, bytesRead, 0, "fileDataParameter");
 free(buffer);
 //lr_log_message("File contents: %s", lr_eval_string("{fileDataParameter}"));

0 个答案:

没有答案