Good answer, thank you. That makes sense. I was surprised to hear Tom W's answer, but couldn't find any other good answers on the web. If OO languages were to be implemented in the way I had originally thought, that sounds like a major weakness and a major use of memory.
lss123 19 Newbie Poster
Ok, so that doesn't sound very efficient. How, then, can an object that is used hundreds, or even thousands of times whose class has a long list of procedures and/or functions, be efficient? It sounds to me that by encapsulating procedures, constants, or whatever inside a class that has thousands of instances, there's a lot of unnecessary repetition of code?
Am I overestimating how much memory is actually used? Even with thousands of objects whose procedure definitions are stored in memory again and again, is it maybe still not a lot of memory being used?
Or am I hitting upon one of the weaknesses of the object-oriented approach?
lss123 19 Newbie Poster
I understand garbage collection, but all of these word objects will be in memory and referenceable (made up my own word there) throughout the entire course of the program. I'm designing it that way for specific reasons.
So really what I'm asking is, is that for any object created that has a number of functions, procedures, and maybe constants defined - are these functions/procedures/constants taking up memory for each object defined? For instance, if a word object has the function "getWord()" defined in memory, if I create 50 word objects, will "getWord()" be defined in memory 50 separate places?
lss123 19 Newbie Poster
Hello- I'm using VB.NET (visual studio) to create a chatbot (a program that mimics a human and has a text converstion with you). Two of my main classes are a word class and a sentence class. The sentence object is basically going to be a linked list of words objects.
Here's my question: as the program executes, many word objects will be instantiated, and so will many sentence objects. But, each class (used to create the object) has several constants, procedures, and functions defined. For each object instantiated, are new copies of the constants, procedures, and functions created in memory? Or, is only one copy of the constants and procedures created?
I hope my question is clear. My fear is that, since many many objects will be created during program execution (each word of a sentence will be an object), that if the constants/procedures/functions are defined in memory again and again, that I'll run out of memory.
If this is the case, what is the best way to structure my program so that the objects created contain only the variable data, and the constants/procedures/functions are defined only once?
lss123 19 Newbie Poster
catchmrbharath, can you be more specific about the problem? What is the input source(s)? What kind of processing has to be done? One of the ways I can attempt to find a solution is to play around with it, but I need to know more about the actual problem first before I can setup my own simulation.
lss123 19 Newbie Poster
Good work !!! But file access every time can be time taking,so,may be you can implement a sudoku board with linked list or a hash table so that traversal can get faster.
The only time it accesses a file is at the beginning, when it reads it in line by line. Are you saying I could store the incoming data into a linked list or hash table? Wouldn't that still require me to access the file the same 9 times to read in the puzzle?
lss123 19 Newbie Poster
I just wanted to post the code I wrote for an OO C++ solution to solving sudoku puzzles. I'd like to invite anyone to ask questions, give comments, or make critiques on the methods or algorithms in the code.
For a recent job interview, I was tasked with writing a sudoku solver. I chose C++ and an object-oriented approach and wrote the first program to mimic my human search methods. I've since refined it to a more algorithm-oriented approach, but still using objects. The main file and header file for the two classes I used (a class "board" and a class "square") are included below. I'm happy to post the implementation of both classes if requested.
This is a command-line program that takes in a file in the format
1....7.9.
.3..2...8
..96..5..
..53..9..
.1..8...2
6....4...
3......1.
.4......7
..7...3..
with the '.' character being a blank. It will detect most invalid puzzles, and should be able to find a solution to any sudoku puzzle. It uses recursion in several places, which I am particularly happy with.
MAIN.CPP:
/********************************************
*
* Module: main.cpp
* Author: Louis Savalli
* Purpose: Implements a Sudoku solver program.
* The user is prompted to enter a file
* containing the sudoku puzzle, and
* this program prints the solved puzzle
* to the console.
*
********************************************/
#include <iostream>
#include <ios>
#include <fstream>
#include <stdlib.h>
#include "sudoku_utils.h"
void give_num_to_square(board & inBoard, int row, …
lss123 19 Newbie Poster
In response to the above question, the program provided is just an example program to illustrate the bug. That is why I declare ifstream. There is no logical purpose, just an illustration of the problem I'm having.
I've found a work-around, so I'm going to go forward with that. Here's the epilogue to this thread:
1) I narrowed down the problem to the Borland linker, ilink32.exe. I did this by copying the two commands from borland (one command for the compiler, and one for the linker) and trying them outside of codeblocks. The compiler commands (bcc32 -c) both outside and inside codeblocks produce almost identical files, so I concluded that isn't the problem. However the linker command, when used both outside and inside codeblocks, produces an executable with the same error -- so, the this is how I narrowed the problem down to the linker (and not a codeblocks bug). Strangely, when I simply call bcc32 without the "-c" option, the executable created works fine. So, compiling using bcc32 to an object file, then linking to an executable is when the problem happens. I'd love to find out exactly why, but I must move on.
2) Why did I say earlier that it failed with the GCC compiler as well? This may be a bug in codeblocks. In mid project, I switched my compiler from borland to GCC, and at this point the program didn't even compile. I misread the results, and assumed my error was the …
Dave Sinkula commented: Great followup. +19
lss123 19 Newbie Poster
Thanks to all for your replies and trials.
Do one thing:
Go to the compiler and just try to comment out the lineifstream inFile;
Check if it runs or not. If it does, tell us. If it doesn't Try to comment-out#include <fstream>
.
If it now runs, tell us. If it doesn't, there is some problem in your compiler or perhaps the linker as it cannot run a simple helloworld program.
I did try that before and found it ran fine without the ifstream declaration.
What are the exact versions and compiler commands executed?
Borland 5.5 and and I'm not sure which version of GCC codeblocks is using, but my version of codeblocks is 8.02 downloaded a month ago. Strange, but when I select the GCC compiler in codeblocks, the executable is mingw32-g++.exe - so I'm not sure exactly what this means. For the Borland compiler, the command used by codeblocks is:
bcc32.exe -q -w -x -O2 -I"C:\Program Files\Borland\BDS\4.0\include" -oobj\Release\main.obj -c main.cpp
I've reinstalled codeblocks a few times, so that's not it. I did manually run the Borland compiler with the command:
bcc32 -If:\Borland\bcc55\include -Lf:\Borland\bcc55\Lib <filename>
and ran it from the command line and that version ran successfully. I tried running the codeblocks-compiled code (same program, just compiled within codeblocks instead of manually at the command line), and that failed just like when run from within codeblocks.
So, my next step is to take the command run by codeblocks, …
lss123 19 Newbie Poster
In a program I am writing, the one line of declaring an ifstream object causes the program to "crash" and a non-zero return code to be returned. Instead of pasting the full program here, I'll paste a sample program that "crashes" just the same.
I put "crash" in quotations because the program will run to completion, but I will get an error message in Vista saying "your program has stopped working" and the program will return a non-zero error. In XP, I don't get the pop-up message, but I do get the non-zero number returned. It's the same non-zero return code each time, but I haven't figured out what it means.
First, some background info:
OS this happens in: Vista and XP
IDE being used: Codeblocks 8.02
Compilers tried: GCC and Borland
Main returns: -1073741819
Second, here is the program that fails with the aforementioned error:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
cout << "Hello world!" << endl;
return 0;
}
In the console, I get:
Hello world!
Process returned -1073741819 (0xC0000005) execution time : 4.137 s
Press any key to continue.
If I remove the ifstream declaration, I get:
Hello world!
Process returned 0 (0x0) execution time : 0.051 s
Press any key to continue.