Click here to Skip to main content
15,906,816 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to make a c++ executable Pin
Member 139824711-Oct-18 8:54
Member 139824711-Oct-18 8:54 
AnswerRe: How to make a c++ executable Pin
Member 140094495-Oct-18 15:30
Member 140094495-Oct-18 15:30 
QuestionAccess a class instance based on its ID Pin
meerokh29-Sep-18 6:50
meerokh29-Sep-18 6:50 
AnswerRe: Access a class instance based on its ID Pin
Richard MacCutchan30-Sep-18 1:55
mveRichard MacCutchan30-Sep-18 1:55 
GeneralRe: Access a class instance based on its ID Pin
meerokh30-Sep-18 3:52
meerokh30-Sep-18 3:52 
GeneralRe: Access a class instance based on its ID Pin
Richard MacCutchan30-Sep-18 4:45
mveRichard MacCutchan30-Sep-18 4:45 
QuestionCan anyone tell me if c++ is worth learning? Pin
Member 1398247125-Sep-18 4:11
Member 1398247125-Sep-18 4:11 
AnswerRe: Can anyone tell me if c++ is worth learning? Pin
Dar Brett25-Sep-18 4:49
Dar Brett25-Sep-18 4:49 
GeneralRe: Can anyone tell me if c++ is worth learning? Pin
Member 1398247125-Sep-18 5:00
Member 1398247125-Sep-18 5:00 
GeneralRe: Can anyone tell me if c++ is worth learning? Pin
Dar Brett25-Sep-18 5:02
Dar Brett25-Sep-18 5:02 
GeneralRe: Can anyone tell me if c++ is worth learning? Pin
Member 1398247125-Sep-18 5:06
Member 1398247125-Sep-18 5:06 
GeneralRe: Can anyone tell me if c++ is worth learning? Pin
Dar Brett25-Sep-18 5:19
Dar Brett25-Sep-18 5:19 
GeneralRe: Can anyone tell me if c++ is worth learning? Pin
Member 1398247125-Sep-18 5:21
Member 1398247125-Sep-18 5:21 
AnswerRe: Can anyone tell me if c++ is worth learning? Pin
Joe Woodbury25-Sep-18 5:51
professionalJoe Woodbury25-Sep-18 5:51 
AnswerRe: Can anyone tell me if c++ is worth learning? Pin
CPallini25-Sep-18 21:18
mveCPallini25-Sep-18 21:18 
QuestionCAsynSocket Client Question Pin
ForNow23-Sep-18 4:10
ForNow23-Sep-18 4:10 
AnswerRe: CAsynSocket Client Question Pin
Richard Andrew x6423-Sep-18 5:37
professionalRichard Andrew x6423-Sep-18 5:37 
GeneralRe: CAsynSocket Client Question Pin
ForNow23-Sep-18 5:43
ForNow23-Sep-18 5:43 
AnswerRe: CAsynSocket Client Question Pin
Victor Nijegorodov23-Sep-18 8:23
Victor Nijegorodov23-Sep-18 8:23 
QuestionC Programming Pin
Member 1399372921-Sep-18 22:29
Member 1399372921-Sep-18 22:29 
AnswerRe: C Programming Pin
Victor Nijegorodov21-Sep-18 23:35
Victor Nijegorodov21-Sep-18 23:35 
AnswerRe: C Programming Pin
CPallini23-Sep-18 21:44
mveCPallini23-Sep-18 21:44 
QuestionHow to deallocate memory allocated to a class instance Pin
meerokh21-Sep-18 5:58
meerokh21-Sep-18 5:58 
In constructor of my class WorkPackage, I am allocating a stack to each instance of workpackage and adding it to a queue. When a workpackage gets executed, the allocated stack get released in class destructor. The problem is that my destructor gets called before the execution of workpackage and program crashes with segmentation fault. I looked it up and thought that it is because of when i get the package from the queue:

PackageQueue.cpp
WorkPackage PackageQueue::GetWorkPackage(){
	if (isEmpty())
	    {
		return WorkPackage(); // return an empty work package
	    }
		pthread_mutex_lock(&getlock);
		WorkPackage data=WorkPackageQueue[front];
	    if (front == rear)
	    {
	        rear = -1;
	        front = -1;
	    }

	    else if (front == 0)
	        front = size-1;
	    else
	        front--;
	     pthread_mutex_unlock(&getlock);
	     return WorkPackage(data);
	}


I created a copy contructor to allocate a new stack to the instance in case of deletion after GetWorkPackage function

WorkPackage::WorkPackage(const WorkPackage& rhs){
	Wp_localstack.local_stack= Stack::make_stack();
	m_action=rhs.m_action;
	m_arguments=rhs.m_arguments;
}


But the problem is still there..Need hints to how can i do this correctly. I will provide more code if needed

modified 21-Sep-18 12:07pm.

AnswerRe: How to deallocate memory allocated to a class instance Pin
Victor Nijegorodov21-Sep-18 8:30
Victor Nijegorodov21-Sep-18 8:30 
GeneralRe: How to deallocate memory allocated to a class instance Pin
meerokh21-Sep-18 11:27
meerokh21-Sep-18 11:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.