假设我struct在ANSI C中有这个:
typedef struct _point
{
float x;
float y;
} Point;
Run Code Online (Sandbox Code Playgroud)
这个函数来创建这个struct:
Point createpoint(float x, float y)
{
Point p;
p.x = x;
p.y = y;
return p;
}
Run Code Online (Sandbox Code Playgroud)
这允许我创建一个struct具有此功能,即:
int main()
{
Point pointOne = createpoint(5, 6);
Point pointTwo = createpoint(10, 4);
float distance = calculatedistancefunc(pointOne, pointTwo);
/* ...other stuff */
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有人告诉我这段代码无效,因为在返回之前它struct没有malloc在createpoint(float x, float y)函数中获取,并且struct将被删除.但是,当我使用我struct这样的时候,它似乎没有被删除.
所以我的问题是:我必须malloc这样做struct …
目前我正在学习神经网络,我正在尝试创建一个可以训练识别手写字符的应用程序.对于这个问题,我使用前馈神经网络,当我训练它识别1,2或3个不同的字符时,它似乎有效.但是当我尝试使网络学习超过3个字符时,它将停留在40 - 60%左右的错误百分比.
我尝试了多层和更少/更多的神经元,但我似乎无法正确,现在我想知道前馈神经网络是否能够识别那么多信息.
一些统计:
网络类型:前馈神经网络
输入神经元: 100(10*10)网格用于绘制字符
输出神经元:重新定位的字符数量
有谁知道我的架构中可能存在的缺陷是什么?输入神经元太多了吗?前馈神经网络不具备角色定位能力吗?
ocr artificial-intelligence backpropagation neural-network feed-forward
有很多关于设计和实现编译器的信息,但我找不到任何关于链接器的信息.
我对这些主题很感兴趣,但我找不到任何关于连接子的信息.有没有人知道有关链接器设计和实现的教程,书籍等?
就像在其他语言中一样简单,我似乎无法在d编程语言中找到一个选项,我可以将字符串(例如:"234.32")转换为double/float/real.
使用std.c.stdio库中的atof仅在我使用常量字符串时才有效.(例如:atof("234.32")有效,但atof(tokens[i]);令牌是带有字符串的动态数组不起作用).
如何在d编程语言中将字符串转换或解析为real/double/float?
我有一个由节点组成的图,我需要一个快速算法,在两个节点之间生成一个随机路径.我从头开始设计了几种算法,但似乎无法做到这一点.
要么算法陷入循环,要么当我保留受访节点的记录时,它有时会卡在被访问节点之间.我遇到的另一个问题是我的算法性能太不稳定了.
所以我的问题是; 有没有人知道一个快速稳定的算法,用于无向图中两个可达节点之间的随机路径?
假设我有一个名为"foo"的对象,另一个名为"bar"的对象作为属性.
当"foo"解除分配时,它会自动删除对"bar"的所有引用,以便"bar"也可以解除分配吗?或者"foo"deallocate和"bar"漂浮在某个地方的记忆中?即使所有"bar"的引用都在"foo"中定义.
提前致谢.
iphone garbage-collection memory-management objective-c dealloc
我正在尝试使用D编程语言,并从官方网站(http://www.digitalmars.com/d/download.html)下载了编译器.我正在按照原来的D编程教程和书.但编译器似乎没有识别很多关键字,例如当我尝试使用"immutable"关键字时,编译器会引发"错误:未定义标识符不可变"错误.它与D的许多其他功能一起做到了这一点.
这怎么可能?据我所知,它实际上是官方编译器.
提前致谢,
Marnix van Rijswijk
鉴于下一个代码示例,我无法释放参数const char* expression:
// removes whitespace from a characterarray
char* removewhitespace(const char* expression, int length)
{
int i = 0, j = 0;
char* filtered;
filtered = (char*)malloc(sizeof(char) * length);
while(*(expression + i) != '\0')
{
if(!(*(expression + i) == ' '))
{
*(filtered + j) = *(expression + i);
j++;
}
i++;
}
filtered[j] = '\0';
free(expression); //this doesn't seem to work
return filtered;
}
Run Code Online (Sandbox Code Playgroud)
在我返回此函数之前,我尝试释放表达式参数中的数据,但我似乎无法释放它.
我认为这可能是因为它是一个常数,但我了解到C中的字符数组总是应该是常量.
我得到的错误消息是在行,free(expression)消息是:
expected void* but argument is of type …
是否可以在纯ANSI-C中复制通用数组?
我有这个结构,它包含一个数组(目前用于浮点数)和一些变量,如数组中的变异大小和容量.
typedef struct _CustomArray
{
float* array; //the array in which the objects will be stored
int size; //the current size of the array
int capacity; //the max capacity of the array
} CustomArray;
Run Code Online (Sandbox Code Playgroud)
我使用这个结构,所以我可以在纯C中创建一个数组,我可以在其中添加/删除项目,在需要时动态扩展数组大小等所有"标准"数组所做的事情,除了它只用C制作.现在我想这样做,这样当你初始化这个结构时,你可以设置它应该保存的元素的数据类型,此时它只能存储浮点数据类型,但我想使它能够存储任何数据类型/其他结构.但我不知道这是否可行.
此时制作此数组的函数是:
CustomArray* CustomArray_Create(int initCapacity, /*type elementType*/)
{
CustomArray* customArray_ptr; //create pointer to point at the structure
float* internalArray = (float*)malloc(sizeof(float) * initCapacity); //create the internal array that holds the items
if(internalArray != NULL)
{
CustomArray customArray = { internalArray, 0, initCapacity }; //make the …Run Code Online (Sandbox Code Playgroud) 我对我的代码的性能有疑问.假设我在C中有一个结构点:
typedef struct _CPoint
{
float x, y;
} CPoint;
Run Code Online (Sandbox Code Playgroud)
以及我使用struct的函数.
float distance(CPoint p1, CPoint p2)
{
return sqrt(pow((p2.x-p1.x),2)+pow((p2.y-p1.y),2));
}
Run Code Online (Sandbox Code Playgroud)
我想知道为#define替换这个函数是否是一个明智的想法,
#define distance(p1, p2)(sqrt(pow((p2.x-p1.x),2)+pow((p2.y-p1.y),2)));
Run Code Online (Sandbox Code Playgroud)
我认为它会更快,因为没有函数开销,我想知道我是否应该将这种方法用于我的程序中的所有其他函数来提高性能.所以我的问题是:
我应该用#define替换所有函数以提高代码的性能吗?
c ×4
d ×2
algorithm ×1
ansi-c ×1
arrays ×1
dealloc ×1
dmd ×1
double ×1
feed-forward ×1
free ×1
generics ×1
graph ×1
inline ×1
iphone ×1
linker ×1
malloc ×1
objective-c ×1
ocr ×1
path-finding ×1
performance ×1
pseudocode ×1
search ×1
string ×1
struct ×1
typeof ×1