小编Suv*_*yil的帖子

何时调用mysql_free_result(Resuing mysql_store_result,MYSQL_RES)

我有2个代码(程序)

计划1:

//global variables
MYSQL_RES *res_set;
MYSQL_ROW row;
MYSQL *connect;

int main()
{
 connect=mysql_init(NULL);
 mysql_real_connect(connect, NULL, "root", "suvp" ,"Employees" ,0,NULL,0);

 /*Other Code*/

 mysql_free_result(res_set);
 mysql_close(connect);
}
Run Code Online (Sandbox Code Playgroud)

" 其他代码 "涉及一个for循环,它调用函数来使用相同的函数res_set来存储结果mysql_store_result.如图所示,我mysql_free_result(res_set);在主要结束时只打了一次电话.

valgrind显示still reachable上述情况下的内存问题(我选择忽略).没有其他泄漏.

计划2:

class mysqlClientClass有以下私有变量,

MYSQL *connect;
MYSQL_RES *res_set; 
MYSQL_ROW row;
Run Code Online (Sandbox Code Playgroud)

一些方法(与我的问题相关),

mysqlClientClass::~mysqlClientClass()
{
if(connect!=NULL)
{   
    mysql_free_result(res_set);
    mysql_close(connect);   
}
}
Run Code Online (Sandbox Code Playgroud)

如果用户无法调用closeConnection,析构函数将关闭它(通过检查是否connect设置为NULL或否)

void mysqlClientClass::closeConnection()
{
    mysql_free_result(res_set);
    mysql_close(connect);
    connect = NULL;
}
Run Code Online (Sandbox Code Playgroud)

getResults 是整个代码中使用的唯一方法 mysql_store_result

void mysqlClientClass::getResults(string iQuery)
{
 /* form …
Run Code Online (Sandbox Code Playgroud)

c++ mysql memory-leaks

9
推荐指数
1
解决办法
2855
查看次数

从'void*'到'void*(*)(void*)'c ++的无效转换?

我想使用在pthread_create(),但它总是给我从这个错误中的无效转换void*void* ( * )(void*)

此错误在第3个参数中.有人可以帮我解决这个错误吗?

void Print_data(void *ptr) {
    cout<<"Time of Week = " <<std::dec<<iTOW<<" seconds"<<endl;
    cout<<"Longitude = "<<lon<<" degree"<<endl;
    cout<<"Latitude  = "<<lat<<" degree"<<endl;
    cout<<"Height Above Sea = "<<alt_MSL<<" meters"<<endl;    
  }

int call_thread() 
  {
    pthread_create(&thread, NULL, (void *) &Print_data, NULL);
    return 0;
  }
Run Code Online (Sandbox Code Playgroud)

c++ pthreads

8
推荐指数
2
解决办法
1万
查看次数

C2059语法错误'string'?

extern "C" 
{
#endif
#include <stdint.h>
#include <limits.h>
#include "attributes.h"
}
#endif
Run Code Online (Sandbox Code Playgroud)

我添加了extern "C" { } 然后我得到了C2059 string错误所以我试图使用#endif,现在我有另外4个错误.

Error   1   error C2059: syntax error : 'string'    d:\c-sharp\c++ 
compiling\consoleapplication7\consoleapplication7\libavutil\rational.h 31 1
ConsoleApplication7
Run Code Online (Sandbox Code Playgroud)

我该如何修复此字符串错误?

c c++

7
推荐指数
1
解决办法
1万
查看次数

将查询结果存储在变量中

我有一个查询,其结果我想存储在变量中我该怎么做?我试过了

./hive -e  "use telecom;insert overwrite local directory '/tmp/result' select
avg(a) from abc;"

./hive --hiveconf MY_VAR =`cat /tmp/result/000000_0`;
Run Code Online (Sandbox Code Playgroud)

我能够在MY_VAR中获得平均值,但它需要我的hive CLI,这不是必需的,有没有办法在hive CLI中访问unix命令?

variables hadoop hive

7
推荐指数
2
解决办法
4万
查看次数

在OOZIE-4.1.0中运行多个工作流时出错

我按照http://gauravkohli.com/2014/08/26/apache-oozie-installation-on-hadoop-2-4-1/中的步骤在Linux机器上 安装了oozie 4.1.0

hadoop version - 2.6.0 
maven - 3.0.4 
pig - 0.12.0
Run Code Online (Sandbox Code Playgroud)

群集设置 -

MASTER NODE runnig - Namenode,Resourcemanager,proxyserver.

SLAVE NODE正在运行 -Datanode,Nodemanager.

当我运行单个工作流程时,工作意味着它成功.但是当我尝试运行多个Workflow作业时,即两个作业都处于接受状态 在此输入图像描述

检查错误日志,我深入研究了问题,

014-12-24 21:00:36,758 [JobControl] INFO  org.apache.hadoop.ipc.Client  - Retrying connect to server: 172.16.***.***/172.16.***.***:8032. Already tried 9 time(s); retry policy is RetryUpToMaximumCountWithFixedSleep(maxRetries=10, sleepTime=1000 MILLISECONDS)
2014-12-25 09:30:39,145 [communication thread] INFO  org.apache.hadoop.ipc.Client  - Retrying connect to server: 172.16.***.***/172.16.***.***:52406. Already tried 9 time(s); retry policy is RetryUpToMaximumCountWithFixedSleep(maxRetries=10, sleepTime=1000 MILLISECONDS)
2014-12-25 09:30:39,199 [communication thread] INFO  org.apache.hadoop.mapred.Task  - Communication exception: …
Run Code Online (Sandbox Code Playgroud)

java hadoop mapreduce oozie oozie-coordinator

7
推荐指数
1
解决办法
3566
查看次数

为什么要破坏pthread_cond_t和pthread_mutex_t?

如果在线程代码中,我在C中创建pthread_cond_t c;条件变量或互斥锁pthread_mutex_t m;,建议在完成所有工作后销毁它们.

为什么会这样?

另外,为什么在cond使用pthread_cond_init();函数动态初始化变量时必须销毁变量.

引用David Butenhof" 用POSIX线程编程 "

"当你动态初始化一个条件变量时,你应该在你不再需要它时通过调用pthread_cond_destroy来销毁条件变量.你不需要销毁一个使用PTHREAD_COND_INITIALIZER宏静态初始化的条件变量"

c multithreading posix pthreads

6
推荐指数
1
解决办法
1504
查看次数

类型转换整数为void*

#include <stdio.h>
void pass(void* );
int main()
{
    int x;
    x = 10;
    pass((void*)x);
    return 0;
}
void pass(void* x)
{
   int y = (int)x;
   printf("%d\n", y);
}


output: 10
Run Code Online (Sandbox Code Playgroud)

我的问题来自上面的代码..

  1. 当我们将正常变量强制转换为void*或任何指针变量时会发生什么?

  2. 我们必须将变量的地址传递给函数,因为在函数定义参数中是指针变量.但是这段代码传递了正常变量..

在linux pthread编程中遵循这种格式......我是一个入门级的C程序员.我在linux gcc编译器中编译这个程序..

c linux pointers pthreads void-pointers

6
推荐指数
1
解决办法
2万
查看次数

`没有main()的Cpp类中对`main`的未定义引用

我试图找到答案时遇到了这个问题.但似乎海报有多个文件,而且它们没有被链接,因而错误.

但是,为什么在使用单个文件时会出现此错误?

g++ myClass.cpp  
/usr/lib/gcc/i686-redhat-linux/4.6.3/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

为什么main在编译时需要这里(从哪里可以看到我的代码中提到main)?main是代码执行的起点,但为什么编译器假设我需要一个main.我可以在其他文件中定义它并用于gcc -o制作可执行文件吗?

或者我可能在代码中遗漏了导致错误的其他内容?

#include<iostream>
class myClass
{

public:
myClass()
{
    std::cout<<"Constructor";
}

~myClass()
{
    std::cout<<"Destructor";    
}

};
Run Code Online (Sandbox Code Playgroud)

c++ g++

6
推荐指数
2
解决办法
2万
查看次数

命名空间混乱

我是命名空间的新手,并且正在尝试使用C++ Primer

#include<iostream>
namespace Jill 
{
 double bucket;
 double fetch;
 struct Hill{ };
}

double fetch;

int main()
{
 using namespace Jill;
 Hill Thrill;
 double water = bucket; 
 //double fetch; //<<<<<<<<<<<<//
 std::cin>> fetch;
 std::cin>> ::fetch;
 std::cin>> Jill::fetch;
 std::cout<<"fetch is "<<fetch;
 std::cout<<"::fetch is "<< ::fetch;
 std::cout<<"Jill::fetch is "<< Jill::fetch;
}

int foom()
{
 Jill::Hill top;
 Jill::Hill crest;
}
Run Code Online (Sandbox Code Playgroud)

当标记的行//<<<<<<<<<<<<//未注释时,我得到预期的结果.即 local变量隐藏globalJill::fetch.但是当我发表评论时,剩下2个.global fetchJill::fetch.编译器会给出错误

namespaceTrial1.cpp:17:13: error: reference to ‘fetch’ is ambiguous
namespaceTrial1.cpp:9:8: …
Run Code Online (Sandbox Code Playgroud)

c++ namespaces

5
推荐指数
1
解决办法
535
查看次数

获取 OOZIE 错误 E0900:不允许 Jobtracker [localhost:8021],不在 Oozies 白名单中]

我正在尝试在 CDH 虚拟机上运行 Oozie 示例。我运行了 Cloudera Manager 并执行以下命令:

oozie job -oozie http://localhost:11000/oozie -config examples/apps/map-reduce/job.properties -run
Run Code Online (Sandbox Code Playgroud)

当我检查状态时,我收到了 HadoopAccessorException。

我检查了 oozie 日志,看到以下堆栈跟踪:

2013-07-22 14:25:56,179 WARN org.apache.oozie.command.wf.ActionStartXCommand:
USER[cloudera] GROUP[-] TOKEN[] APP[map-reduce-wf] JOB[0000001-130722142323751-oozie
oozi-W] ACTION[0000001-130722142323751-oozie-oozi-W@mr-node] Error starting action
[mr-node]. ErrorType [ERROR], ErrorCode [HadoopAccessorException], Message
[HadoopAccessorException: E0900: Jobtracker  not allowed, not in
Oozies whitelist] org.apache.oozie.action.ActionExecutorException:
HadoopAccessorException: E0900: Jobtracker not allowed, not in Oozies
Whitelist
Run Code Online (Sandbox Code Playgroud)

oozie-site.xml 和 oozie-default.xml设置了oozie.service.HadoopAccessorService.jobTracker.whitelistoozie.service.HadoopAccessorService.nameNode.whitelist

任何帮助,将不胜感激。

谢谢。

戴夫

hadoop oozie

5
推荐指数
1
解决办法
4583
查看次数