我对一个错误非常绝望,我无法克服.
对于我在大学的C编程课,我必须为GML(图形建模语言)输入流实现一个解析器.
成功时,解析器将一个Abstract数据类型返回给调用者,调用者是一个Adjacency Matrix,作为图的表示.
好的,解析器工作完美无缺,在过去的几天里不会出现让我绝望的问题.在解析器中,有一个函数调用,它又调用malloc.在扫描程序中,逐个符号地向解析器传递malloc.但是在离开扫描程序之前调用free()总是释放malloc'd mem块.
但是在解析器中有一个致命的函数调用,它反过来调用一个函数,该函数使用malloc来保存12个字节的内存(三个整数属性)来保存结构.需要结构来存储关于图中单个边的信息(源节点,目标节点,权重).
这次通话是两次.第一次,一切顺利.然后,由于根据gml语法可能出现1到n个边,因此代码进入while循环,其中为同一指针分配指向新Edge Struct的指针,只要在输入流中找到Edges即可.循环中第一次调用边缘识别例程,总共第二次调用(第一个在进入循环之前发生,参见ma),由malloc返回NULL不断失败.
我根本不知道为什么.
它不是关于内存不足的问题,因为当我在该程序的main()函数中使用malloc 1000字节时,只是为了好玩,它工作正常.
我使用Code :: Blocks和DevCPP作为IDE.在两者中,程序遇到同样的问题.
这是我的主要解析例程:
DirectedGraph Graph(char* sourceString, int*currentPosition){
int sym;
int restartPosition = 0;
int* backupPosition;
char* backupString;
int nodeCount = 0;
int currentSrc = -1;
int currentTgt = -1;
int currentWgt = -1;
EdgeDescription e;
DirectedGraph correctMatrix;
MatrixStruct* errorMatrix = NULL;
/*begin parsing*/
bool isGraphHeader = GraphHdr(sourceString, currentPosition);
if(isGraphHeader == true){
bool isNode = Node(sourceString, currentPosition);
if(isNode == true){
while(isNode == true){
nodeCount++;
restartPosition = *currentPosition;
isNode …Run Code Online (Sandbox Code Playgroud) 我必须在WPF项目中实现一个简单的柱形图输出.我为它选择了OxyPlot库.设计模式当然是MVVM.相关的源代码部分可以在下面看到.我得到的,当我运行项目时是一个空图表,x轴上的类别为1到5(这是正确的),y轴上的值为0到100(这也是正确的,因为我应该显示百分比) .
数据集合(类别轴的"难点"和值轴的"百分比")正确填充了值,我检查了一个.
但是没有显示任何列.所以我想知道我做错了什么.我根据这个oxyplot演示构建了我的示例,并基于我们在大学的wpf课程中提供的示例.
有什么建议?
关心罗兰
using System;
using System.ComponentModel;
using System.Linq.Expressions;
namespace GeoCaching.Wpf.ViewModels
{
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
protected void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
Console.WriteLine("PropertyChangedEventArgs called " + propertyName);
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
统计模型本身就在这里:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using …Run Code Online (Sandbox Code Playgroud)