Search Results

Search found 12267 results on 491 pages for 'out of memory'.

Page 139/491 | < Previous Page | 135 136 137 138 139 140 141 142 143 144 145 146  | Next Page >

  • Why does my C++ LinkedList method print out the last word more than once?

    - by Anthony Glyadchenko
    When I call the cmremoveNode method in my LinkedList from outside code, I get an EXC_BAD_ACCESS. FIXED: But now the last word using the following test code gets repeated twice: #include <iostream> #include "LinkedList.h" using namespace std; int main (int argc, char * const argv[]) { ctlinkList linkMe; linkMe.cminsertNode("The"); linkMe.cminsertNode("Cat"); linkMe.cminsertNode("Dog"); linkMe.cminsertNode("Cow"); linkMe.cminsertNode("Ran"); linkMe.cminsertNode("Pig"); linkMe.cminsertNode("Away"); linkMe.cmlistList(); cout << endl; linkMe.cmremoveNode("The"); linkMe.cmremoveNode("Cow"); linkMe.cmremoveNode("Away"); linkMe.cmlistList(); return 0; } LinkedList code: /* * LinkedList.h * Lab 6 * * Created by Anthony Glyadchenko on 3/22/10. * Copyright 2010 __MyCompanyName__. All rights reserved. * */ #include <stdio.h> #include <iostream> #include <fstream> #include <iomanip> using namespace std; class ctNode { friend class ctlinkList ; // friend class allowed to access private data private: string sfileWord ; // used to allocate and store input word int iwordCnt ; // number of word occurrances ctNode* ctpnext ; // point of Type Node, points to next link list element }; class ctlinkList { private: ctNode* ctphead ; // initialized by constructor public: ctlinkList () { ctphead = NULL ; } ctNode* gethead () { return ctphead ; } string cminsertNode (string svalue) { ctNode* ctptmpHead = ctphead ; if ( ctphead == NULL ) { // allocate new and set head ctptmpHead = ctphead = new ctNode ; ctphead -> ctpnext = NULL ; ctphead -> sfileWord = svalue ; } else { //find last ctnode do { if ( ctptmpHead -> ctpnext != NULL ) ctptmpHead = ctptmpHead -> ctpnext ; } while ( ctptmpHead -> ctpnext != NULL ) ; // fall thru found last node ctptmpHead -> ctpnext = new ctNode ; ctptmpHead = ctptmpHead -> ctpnext ; ctptmpHead -> ctpnext = NULL; ctptmpHead -> sfileWord = svalue ; } return ctptmpHead -> sfileWord ; } string cmreturnNode (string svalue) { return NULL; } string cmremoveNode (string svalue) { int counter = 0; ctNode *tmpHead = ctphead; if (ctphead == NULL) return NULL; while (tmpHead->sfileWord != svalue && tmpHead->ctpnext != NULL){ tmpHead = tmpHead->ctpnext; counter++; } do{ tmpHead->sfileWord = tmpHead->ctpnext->sfileWord; tmpHead = tmpHead->ctpnext; } while (tmpHead->ctpnext != NULL); return tmpHead->sfileWord; } string cmlistList () { string tempList; ctNode *tmpHead = ctphead; if (ctphead == NULL){ return NULL; } else{ while (tmpHead != NULL){ cout << tmpHead->sfileWord << " "; tempList += tmpHead->sfileWord; tmpHead = tmpHead -> ctpnext; } } return tempList; } }; Why is this happening?

    Read the article

  • Any ideas for developing a Risc Processor friendly string allocator?

    - by Richard Fabian
    I'm working on some tools to enable high throughput data-oriented development, and one thing that I've not got an immediate answer for is how you go about allocating strings quickly. On risc processors you've got another problem of implementation that the CPU doesn't like branching, which is what I'm trying to minimise or avoid. Also, cache coherence is important on most CPUs, so that's gotta be influential in the design too. So, how would you go about reducing the overhead for a generic string allocator? Sometimes it's easier to solve a more explicit problem, so any ideas for string sizes of 5-30?

    Read the article

  • Getting a seg fault, having trouble with classes and variables.

    - by celestialorb
    Ok, so I'm still learning the ropes of C++ here so I apologize if this is a simple mistake. I have this class: class RunFrame : public wxFrame { public: RunFrame(); void OnKey(wxKeyEvent& keyEvent); private: // Configuration variables. const wxString *title; const wxPoint *origin; const wxSize *size; const wxColour *background; const wxColour *foreground; const wxString *placeholder; // Control variables. wxTextCtrl *command; // Event table. DECLARE_EVENT_TABLE() }; ...then in the OnKey method I have this code: void RunFrame::OnKey(wxKeyEvent& keyEvent) { // Take the key and process it. if(WXK_RETURN == keyEvent.GetKeyCode()) { bool empty = command -> IsEmpty(); } // Propogate the event through. keyEvent.Skip(); } ...but my program keeps seg faulting when it reaches the line where I attempt to call the IsEmpty method from the command variable. My question is, "Why?" In the constructor of the RunFrame class I can seemingly call methods for the command variable in the same way I'm doing so in the OnKey method...and it compiles correctly, it just seg faults on me when it attempts to execute that line. Here is the code for the constructor if necessary: RunFrame::RunFrame() : wxFrame(NULL, wxID_ANY, wxT("DEFAULT"), wxDefaultPosition, wxDefaultSize, wxBORDER_NONE) { // Create the styling constants. title = new wxString(wxT("RUN")); origin = new wxPoint(0, 0); size = new wxSize(250, 25); background = new wxColour(33, 33, 33); foreground = new wxColour(255, 255, 255); placeholder = new wxString(wxT("command")); // Set the styling for the frame. this -> SetTitle(*title); this -> SetSize(*size); // Create the panel and attach the TextControl to it. wxPanel *panel = new wxPanel(this, wxID_ANY, *origin, *size, wxBORDER_NONE); // Create the text control and attach it to the panel. command = new wxTextCtrl(panel, wxID_ANY, *placeholder, *origin, *size); // Set the styling for the text control. command -> SetBackgroundColour(*background); command -> SetForegroundColour(*foreground); // Connect the key event to the text control. command -> Connect(wxEVT_CHAR, wxKeyEventHandler(RunFrame::OnKey)); // Set the focus to the command box. command -> SetFocus(); } Thanks in advance for any help you can give! Regards, celestialorb

    Read the article

  • When to release the UIImage ?

    - by ragnarius
    I use the following code to draw a subimage UIImage* subIm = getSubImage( large, rect ); [subIm drawInRect:self.bounds]; where getSubImage is defined as follows UIImage* getSubImage(UIImage* uim, CGRect rc){ CGImageRef imref = CGImageCreateWithImageInRect(uim.CGImage, rc); UIImage* sub = [UIImage imageWithCGImage:imref]; CGImageRelease(imref); NSLog(@"subimage retainCount=%d", [sub retainCount]); // is 1 return sub; }//getSubImage Is the code correct? Is it safe to "CGImageRelease" imref? Has sub "CGImageRetained" imref? Should I release subIm (I get an error if I do)? Is subIm contained in the autorelease-pool, and , if so, how do I know this? In general, can one check if an object is contained in the autorelease pool (for debugging purpose)?

    Read the article

  • Should a g_object_new have a matching g_object_unref?

    - by legends2k
    I'm using libnotify to show desktop notifications in my application; notify_notification_new() returns a NotifyNotification*, which should be passed as the first param to further function calls of the notification library. There is no notify_notification_free() which frees the pointer it returns. I looked up the source of notify_notification_new() and internally it does a g_object_new(), gets a GObject* and returns it as a NotfiyNotification*, so when my application does the clean up, should I call a g_object_unref() on the pointer returned by notify_notification_new()?

    Read the article

  • How to query the video ram size of a ATI card on Linux?

    - by Patrick Bao
    I want to know the physical video ram size in my application. I can get the same information of Nvidia card by using "nvidia-settings -q -t VideoRam". I can use amdcccle to find this information, but it's an GUI app, so can't be used in my application. I wonder if there is a way to get this by command, function, or config file? I'm using RHEL 5.4.

    Read the article

  • dealloc properties with assign and readwrite objective-c

    - by okami
    I have this structure: @interface MyList : NSObject { NSString* operation; NSString* link; } @property (readwrite) NSString* operation; @property (readwrite, assign) NSString* link; @end @implementation MyList @synthesize operation,link; @end I know that if I had retain instead of readwrite I should release the operation and link properties. BUT should I release the operation and link with the code above?

    Read the article

  • Exemple where TYPE_ALIGNMENT() fails

    - by JustMaximumPower
    Hi, I have a question relating to alignment in c/c++. In http://stackoverflow.com/questions/364483/determining-the-alignment-of-c-c-structures-in-relation-to-its-members Michael Burr posted this Makro: #define TYPE_ALIGNMENT( t ) offsetof( struct { char x; t test; }, test ) in the comments someone wrote this might fail with non POD typs. Can someone give me an code example where this fails?

    Read the article

  • Objective-c garbage collection

    - by Chris
    If garbage collection is not required: - (void) awakeFromNib{ //Create the NSStatusBar and set its length statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; ... Do I have to release that? And if I do, would that be in a finalize method or dealloc method? If garbage collection is required, then is the retain call above ignored automatically?

    Read the article

  • leak in fgets when assigning to buffer

    - by monkeyking
    I'm having problems understanding why following code leaks in one case, and not in the other case. The difference is while(NULL!=fgets(buffer,length,file))//doesnt leak while(NULL!=(buffer=fgets(buffer,length,file))//leaks I thought it would be the same. Full code below. #include <stdio.h> #include <stdlib.h> #define LENS 10000 void no_leak(const char* argv){ char *buffer = (char *) malloc(LENS); FILE *fp=fopen(argv,"r"); while(NULL!=fgets(buffer,LENS,fp)){ fprintf(stderr,"%s",buffer); } fclose(fp); fprintf(stderr,"%s\n",buffer); free(buffer); } void with_leak(const char* argv){ char *buffer = (char *) malloc(LENS); FILE *fp=fopen(argv,"r"); while(NULL!=(buffer=fgets(buffer,LENS,fp))){ fprintf(stderr,"%s",buffer); } fclose(fp); fprintf(stderr,"%s\n",buffer); free(buffer); }

    Read the article

  • Can't process UIImage from UIImagePickerController and app crashes..

    - by eimaikala
    Hello guys, I am new to iPhone sdk and can't figure out why my application crashes. In the .h I have: UIImage *myimage; //so as it can be used as global -(IBAction) save; @property (nonatomic, retain) UIImage *myimage; In the .m I have: @synthesize myimage; - (void)viewDidLoad { self.imgPicker = [[UIImagePickerController alloc] init]; self.imgPicker.allowsImageEditing = YES; self.imgPicker.delegate = self; self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { myimage = [[info objectForKey:UIImagePickerControllerOriginalImage]retain]; [picker dismissModalViewControllerAnimated:YES]; } -(IBAction) process{ myimage=[self process:myimage var2:Val2 var3:Val3 var4:Val4]; UIImageWriteToSavedPhotosAlbum(myimage, nil, nil, nil); [myimage release]; } When the button process is clicked, the application crashes and really I have no idea why this happens. When i change it to: -(IBAction) process{ myimage =[UIImage imageNamed:@"im1.jpg"]; myimage=[self process:myimage var2:Val2 var3:Val3 var4:Val4]; UIImageWriteToSavedPhotosAlbum(myimage, nil, nil, nil); [myimage release]; } the process button works perfectly... Any help would be appreciated. Thanks in advance

    Read the article

  • Where I should call [object release] ?

    - by mongeta
    Hello, I've subclassed some UITextField and added some custom properties. In a UITableViewController, in the ViewDiDLoad I init them, and in the cellForRowAtIndexPath I add them to the cell with [cell.contentView addSubview:customTextField]; Each cell has a different customTextField as all of them are very different. Where I should call the [customTextField release] ? After I add them to the cell view ? If for example I call [self.tableView reloadData] my customTextField are going to be added again to the cell, so maybe I should change my approach in doing this ? thanks for the orientation ... regards, r.

    Read the article

  • Effect of 'myObj = [[[[MyClass alloc] init] autorelease] retain];'?

    - by filipe
    I've just downloaded the Facebook iOS SDK and I noticed that in the sample code that comes with the SDK whenever it creates an instance of the Facebook class it does it like this: _facebook = [[[[Facebook alloc] init] autorelease] retain]; where _facebook is a member variable of the calling object (i.e. not a local variable). Can anyone explain exactly what's the point of autoreleasing and then retaining it?

    Read the article

  • How to solve the leaks when allocating the NSMutableArray in Objective-C

    - by Madan Mohan
    Hi Guys, I am getting leaks in Master view controller of iPhone. When I call this method, I am inserting them into filteredListCount array, because when I search I need to show the list from filteredListCount array otherwise customerArray. This functionality is working fine but I am getting leaks in the method below at allocation: filteredListCount = [[NSMutableArray alloc] initWithCapacity: [customerArray count]]; This is the first view controller of my application, I am showing the list and I am also allowing to search from a list. - (void)parser:(CustomerListLibXmlParser *)parser addCustomerObject:(Customer *)customerObj1 { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [customerArray addObject:customerObj1]; filteredListCount = [[NSMutableArray alloc] initWithCapacity: [customerArray count]]; [filteredListCount addObjectsFromArray: customerArray]; [theTableView reloadData]; } - (void)parser:(CustomerListLibXmlParser *)parser encounteredError:(NSError *)error { } - (void)parserFinished:(CustomerListLibXmlParser *)parser { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; self.title=@"Customers"; }

    Read the article

  • How can I get type information at runtime from a DMP file in a Windbg extension?

    - by pj4533
    This is related to my previous question, regarding pulling objects from a dmp file. As I mentioned in the previous question, I can successfully pull object out of the dmp file by creating wrapper 'remote' objects. I have implemented several of these so far, and it seems to be working well. However I have run into a snag. In one case, a pointer is stored in a class, say of type 'SomeBaseClass', but that object is actually of the type 'SomeDerivedClass' which derives from 'SomeBaseClass'. For example it would be something like this: MyApplication!SomeObject +0x000 field1 : Ptr32 SomeBaseClass +0x004 field2 : Ptr32 SomeOtherClass +0x008 field3 : Ptr32 SomeOtherClass I need someway to find out what the ACTUAL type of 'field1' is. To be more specific, using example addresses: MyApplication!SomeObject +0x000 field1 : 0cae2e24 SomeBaseClass +0x004 field2 : 0x262c8d3c SomeOtherClass +0x008 field3 : 0x262c8d3c SomeOtherClass 0:000> dt SomeBaseClass 0cae2e24 MyApplication!SomeBaseClass +0x000 __VFN_table : 0x02de89e4 +0x038 basefield1 : (null) +0x03c basefield2 : 3 0:000> dt SomeDerivedClass 0cae2e24 MyApplication!SomeDerivedClass +0x000 __VFN_table : 0x02de89e4 +0x038 basefield1 : (null) +0x03c basefield2 : 3 +0x040 derivedfield1 : 357 +0x044 derivedfield2 : timecode_t When I am in WinDbg, I can do this: dt 0x02de89e4 And it will show the type: 0:000> dt 0x02de89e4 SomeDerivedClass::`vftable' Symbol not found. But how do get that inside an extension? Can I use SearchMemory() to look for 'SomeDerivedClass::`vftable'? If you follow my other question, I need this type information so I know what type of wrapper remote classes to create. I figure it might end up being some sort of case-statement, where I have to match a string to a type? I am ok with that, but I still don't know where I can get that string that represents the type of the object in question (ie SomeObject-field1 in the above example).

    Read the article

  • Is there performance to be gained by moving storage allocation local to a member function to its cla

    - by neuviemeporte
    Suppose I have the following C++ class: class Foo { double bar(double sth); }; double Foo::bar(double sth) { double a,b,c,d,e,f a = b = c = d = e = f = 0; /* do stuff with a..f and sth */ } The function bar() will be called millions of times in a loop. Obviously, each time it's called, the variables a..f have to be allocated. Will I gain any performance by making the variables a..f members of the Foo class and just initializing them at the function's point of entry? On the other hand, the values of a..f will be dereferenced through this-, so I'm wondering if it isn't actually a possible performance degradation. Is there any overhead to accessing a value through a pointer? Thanks!

    Read the article

  • EXEC_BAD_ACCESS error comes in my applicatoin in iphone

    - by Jaimin
    when i print dictionary i got this error.. here my dictTf is mutabledictionay.. when i m in home page i selct few fields and click find. so new view comes with the result.. now i go back and again click find without changing anything.. now comes proper.. now at this moment when i go back it shows this in the dictionay and EXEC_BAD_ACCESS eror comes... Printing description of dictTf: The program being debugged was signaled while in a function called from GDB. GDB has restored the context to what it was before the call. To change this behavior use "set unwindonsignal off" Evaluation of the expression containing the function (CFShow) will be abandoned. The program being debugged was signaled while in a function called from GDB. GDB has restored the context to what it was before the call. To change this behavior use "set unwindonsignal off" Evaluation of the expression containing the function (CFShow) will be abandoned. (gdb)

    Read the article

  • vector <T *> destructor

    - by Daniel.Z
    I have a class defined like: Class A { public: int num; A *parent; vector<A *> children; ... // constructor without parameters A(void) { this->num = 3; this->parent = 0; for (int i=0;i<num;++i) children.push_back(new A(this,num-1)); } // constructor with parameters A(A *a,int n) { this->num = n; this->children->parent = a; for (int i=0;i<num;++i) this->children.push_back(new A(this,this->num-1)); } }; now, the constructor works fine. there are some problem with destructor. currently, the destructor is defined as: A::~A(void) { if (this->parent!=0) this->parent = 0; for (int i=0;i<(int)children.size();++i) this->children[i]->~A(); vector <A *> ().swap(this->children); } but every time when I debug it, it will break at: void deallocate(pointer _Ptr, size_type) { // deallocate object at _Ptr, ignore size ::operator delete(_Ptr); } it looks like I cannot delete the pointer in the vector of this-children, is there any way that I can de-construct the class successfully?

    Read the article

  • App crashes every second time a tableview row is selected in navigation controller setup

    - by Thaurin
    Disclaimer first: I'm pretty new to Objective-C and the retain model. I've been developing in a garbage collected .NET environment for the last five years, so I've been spoiled. I'm still learning. I'm having my iPhone app crash with EXC_BAD_ACCESS. It happens in a navigtation controller/tableview setup. When I select a row the first time, no problems. It switches in the child controller without problems. I go back and select the same row again. Program then proceeds to crash. Every other row works fine, but every second time a row is accessed, it's a crash. I've pinpointed the location where this happens. The child controller (which is a class that I reuse for every row of the same type) that's being switched into has an array of NSString's representing the rows that will be displayed. I set it before pushing the child viewcontroller. It's there where this apparently happens. I'm having a hard time debugging this problem, still wrestling with xcode and all. I fear there may be some vital information missing here, but maybe there is something you recognize here.

    Read the article

  • Retain cycle on `self` with blocks

    - by Jonathan Sterling
    I'm afraid this question is pretty basic, but I think it's relevant to a lot of Objective-C programmers who are getting into blocks. What I've heard is that since blocks capture local variables referenced within them as const copies, using self within a block can result in a retain cycle, should that block be copied. So, we are supposed to use __block to force the block to deal directly with self instead of having it copied. __block typeof(self) bself = self; [someObject messageWithBlock:^{ [bself doSomething]; }]; instead of just [someObject messageWithBlock:^{ [self doSomething]; }]; What I'd like to know is the following: if this is true, is there a way that I can avoid the ugliness (aside from using GC)?

    Read the article

  • Objective-C: when does an assigned object get deallocated

    - by Stefan Klumpp
    If I have a instance method and within this method I do something like this: NSString *peopleString = [peopleList componentsJoinedByString: @", "]; ... UILabel *likeLabel = [[UILabel alloc] initWithFrame:CGRectMake(16.0+6.0f, 4.0f, 252.0f, 12.0f)]; [likeLabel setText:peopleString]; [likeLabel setFont:[UIFont fontWithName:@"Arial" size:12]]; [likeRow addSubview:likeLabel]; [likeLabel release]; The componentsJoinedByString doesn't contain a new, copy or alloc, thus I don't have to release it. What I'm wondering though is, when my peopleString gets deallocated. Might it happen to early? Meaning, before I can set the text in my label. Should I better use a [[NSString alloc] initWithString:[peopleList componentsJoinedByString: @", "]]; and release it at the end of this method?

    Read the article

  • Can get members, but not count of NSMutableArray

    - by Curyous
    I'm filling an NSMutableArray from a CoreData call. I can get the first object, but when I try to get the count, the app crashes with Program received signal: “EXC_BAD_ACCESS”. How can I get the count? Here's the relevant code - I've put a comment on the line where it crashes. - (void)viewDidLoad { [super viewDidLoad]; managedObjectContext = [[MySingleton sharedInstance] managedObjectContext]; if (managedObjectContext != nil) { charactersRequest = [[NSFetchRequest alloc] init]; charactersEntity = [NSEntityDescription entityForName:@"Character" inManagedObjectContext:managedObjectContext]; [charactersEntity retain]; [charactersRequest setEntity:charactersEntity]; [charactersRequest retain]; NSError *error; characters = [[managedObjectContext executeFetchRequest:charactersRequest error:&error] mutableCopy]; if (characters == nil) { NSLog(@"Did not get results for characters: %@", error.localizedDescription); } else { [characters retain]; NSLog(@"Found some character(s)."); Character* character = (Character *)[characters objectAtIndex:0]; NSLog(@"Name of first one: %@", character.name); NSLog(@"Found %@ character(s).", characters.count); // Crashes on this line with - Program received signal: “EXC_BAD_ACCESS”. } } } And previous declarations from the header file: @interface CrowdViewController : UITableViewController { NSManagedObjectContext *managedObjectContext; NSFetchRequest *charactersRequest; NSEntityDescription *charactersEntity; NSMutableArray *characters; } I'm a bit perplexed and would really appreciate finding out what is going on.

    Read the article

  • NSURLConnection shown as leaking in instruments

    - by Gyozo Kudor
    Hello another stupid question regarding leaks and also NSURLConnection. How do i release it? Is it enough if i release in the following 2 methods? (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error (void)connectionDidFinishLoading:(NSURLConnection *)connection Because in instruments it shows me the line where I alloc my connection as the source of leaking. OK I don't get it. After the following code my urlConnection has a retain count of 2. WTF? NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest: urlRequest delegate: self]; This is the line that instruments points me to. I find this very weird.

    Read the article

  • Getting the front buffer into a gfx mem surface (Dx9)

    - by lapin
    I'm using DirectX 9 to acquire the frontbuffer. There are a couple of ways I know of to get at the front buffer: GetRenderTargetData() GetFrontBufferData() The MSDN page on both of these API calls state that the data is copied from device memory to system memory. I'd like to copy the front buffer surface directly to another graphics memory surface, as I have other manipulations to perform on the acquired surface before returning it to system memory. I'm creating a D3DUSAGE_DYNAMIC texture (gfx mem texture) and calling GetFrontBufferData() to write the front buffer to my textures surface0. Is this valid? Will the operation remain in gfx memory, or will it need to move to system memory and then back to graphics memory? If this is the case, is what I'm trying to achieve possible?

    Read the article

  • Using CreateFileMapping between two programs - C

    - by Jamie Keeling
    Hello, I have two window form applications written in C, one holds a struct consisting of two integers, another will receive it using the CreateFileMapping. Although not directly related I want to have three events in place so each of the processes can "speak" to each other, one saying that the first program has something to pass to the second, one saying the first one has closed and another saying the second one has closed. What would be the best way about doing this exactly? I've looked at the MSDN entry for the CreateFileMapping operation but I'm still not sure as to how it should be done. I didn't want to start implementing it without having some sort of clear idea as to what I need to do. Thanks for your time.

    Read the article

< Previous Page | 135 136 137 138 139 140 141 142 143 144 145 146  | Next Page >