标签: implementation

现代语言和数组符号约定

您是否知道任何现代语言,其中数组被标记为列/行而不是C++/Java/C#row/column中的数组?

arrays implementation programming-languages specifications

-1
推荐指数
1
解决办法
102
查看次数

列表实现中的分段错误(核心转储)[C++]

我知道这对我的第一个问题来说是一个很长的问题,但我已经真的试图在2周内解决这个问题而无济于事.

我很确定我的问题是与记忆相关的问题,即使我已经搜索了其他人的解决方案,我也没有运气.

这是代码:

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef string tElemLista;

typedef struct nodo {
    tElemLista title;
    tElemLista info; // el elemento en sí
    nodo *next; // puntero autoreferencial
    nodo *prev;
    // al proximo nodo
} tNodo;

class tLista {
    tNodo *head;
    tNodo *tail;
    tNodo *curr;
    unsigned int listSize;
    unsigned int pos; // posición actual en la lista
public:
    tLista() {
        head = tail = curr = NULL;
        listSize = 0; // lista vacía …
Run Code Online (Sandbox Code Playgroud)

c++ implementation list core fault

-1
推荐指数
1
解决办法
89
查看次数

这个Singleton类有什么问题吗?

在这些条件下,我编写了下一个Singleton类:
1 - 我想要一个且只有一个类的实例存在并且可以从整个游戏引擎访问.
2 - Singleton被密集使用(每帧数千次)所以我不想写一个额外的GetInstance()函数,我试图避免任何额外的函数调用性能
3 - 一种可能性是让GetInstance()像内联一样这个 :

inline Singleton* Singleton::GetInstance()
{
  static Singleton * singleton = new Singleton();
  return singleton;
}
Run Code Online (Sandbox Code Playgroud)

但这会引起一个引用问题,每次调用时都会有一个对单例的新引用,用于修复用c ++编写的内容:

class Singleton{
private:
    static   Singleton* singleton;
    Singleton(){}

public:
    static inline  Singleton* GetInstance() // now can be inlined !
    {
        return singleton;
    }

    static void Init()
    {
        // ofc i have to check first if  this function
        // is active only once
        if(singleton != nullptr)
        {
            delete singleton;
        }

        singleton = new Singleton();
    } …
Run Code Online (Sandbox Code Playgroud)

c++ singleton implementation static-methods

-2
推荐指数
2
解决办法
641
查看次数

在C中实现最快的fgets

已知的fgets libc函数实现fgetc()在里面使用,如何使用read()更大的缓冲区或其他方法代替加速函数?

例如,我读取/proc/pid/maps文件来搜索一些字符串.该文件的格式是已知的,目前我使用fgets链接中的实现read(fd, &c, 1);代替getc.我认为从文件读取单字节比读取200字节慢.所以我想修改函数从文件读取N个字节,然后找到换行符.我认为替换1字节读取可以以某种方式加速该功能.

c performance implementation libc fgets

-2
推荐指数
1
解决办法
514
查看次数

如何实现我的 parseInt(String str) 方法?

这是我的任务。我不知道如何实现这个方法。

实现一个Integer parseInt(String str)方法抛出NumberFormatException,该方法将取输入字符串,该字符串必须只包含数字且不能从零开始,并返回一个数字,该数字必须从行的转换中获得。不允许使用默认类 Java 的方法。我就是这样解决的:

公共类 Pars {

public static void main(String[] args) {
    String s = " ";
    int res = 0;

    int[] arr = new int[s.length()];
    try {
        for (int i = 0; i < s.length(); i++) {
            arr[i] = s.trim().charAt(i);
        }

        try {
            for (int i = arr.length - 1, j = 1; i >= 0; i--, j *= 10) {
                if ((arr[0] - 48) <= 0 || (arr[i] - 48) >= 10) {
                    throw new …
Run Code Online (Sandbox Code Playgroud)

java implementation parseint

-4
推荐指数
1
解决办法
7317
查看次数