此代码生成随机数,然后根据有关间隔的函数的输入生成直方图."bins"表示直方图间隔,"bin_counts"表示给定间隔中的随机数.
我已经回顾了几个涉及类似问题的帖子,我知道我在某个地方的记忆中已经超出界限但是GBD只指向了"免费(箱子);" 在代码的最后.我已经仔细检查了我的数组长度,我认为它们在不访问不存在的元素/写入未分配的内存方面都是正确的.奇怪的是代码按预期工作,它产生一个准确的直方图,现在我只需要帮助清理这个free()无效的下一个大小错误.如果有人有任何建议我会非常感激.整个输出是:
检测到glibc ./file:free():下一个大小无效(快):0x8429008
然后是内存中的一堆地址,由Backtrace和Memory Map分隔.Backtrace只指向第129行,即"free(bins);".提前致谢
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
void histo(int N, double m, double M, int nbins, int *bin_counts, double *bins);
int main(int argc, char* argv[])
{
int *ptr_bin_counts;
double *ptr_bins;
histo(5,0.0,11.0,4, ptr_bin_counts, ptr_bins);
return 0;
}
void histo(int N, double m, double M, int nbins, int *bin_counts, double *bins)
{
srand(time(NULL));
int i,j,k,x,y;
double interval;
int randoms[N-1];
int temp_M = (int)M;
int temp_m = (int)m;
interval = (M-m) /((double)nbins);
//allocating mem to arrays
bins …Run Code Online (Sandbox Code Playgroud) 我正在研究一些OpenCV代码,并在Windows 2008的VS 2008中开发它.我正在尝试使用g ++在Linux上运行代码,但是我得到错误"无法直接调用构造函数'ImageProcessor :: ImageProcessor'用于ImageProcessor和我创建的所有其他类.我试图找到一种间接调用构造函数的方法,但无济于事.任何建议都会很棒.代码在Windows上编译并运行良好.
if (x == 1){
cout <<"MODE SELECTED: IMAGE TESTING \n";
ImageProcessor* IP = new ImageProcessor;
LaneDetector* LD = new LaneDetector;
LaneInfo* LI1 = new LaneInfo;
LaneInfo* LI2 = new LaneInfo;
LaneVector* LV = new LaneVector;
cvNamedWindow("Window",CV_WINDOW_AUTOSIZE);
IplImage* temp = 0;
IplImage* img0 = 0;
img0 = cvLoadImage(PICTURE_INPUT);
CvRect r = cvRect(0,((img0->height)/3),img0->width,((img0->height)/3)+20);
cout <<"IMG0 LOADED \n";
while(1){
IP->ImageProcessor::ImageProcessor(img0, r);
temp = IP->ImageProcessor::get_processed_image();
LD->LaneDetector::LaneDetector(temp,r);
LD->LaneDetector::find_edges();
LI1 = LD->LaneDetector::find_lanes(5);
LI2 = LD->LaneDetector::find_lanes(25);
LV->LaneVector::LaneVector(LI1,LI2);
LV->LaneVector::print_lane_angle_info();
if( (cvWaitKey(20) & …Run Code Online (Sandbox Code Playgroud)