Skip to main content
deleted 2 characters in body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition (with the delete keyword), you will lose the memory (and this is a memory breachleak). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer (*, because the new keyword creates a pointer), and also Obj and Object are inconsistent types (they should be equal), so:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object object;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition (with the delete keyword), you will lose the memory (and this is a memory breach). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer (*, because the new keyword creates a pointer), and also Obj and Object are inconsistent types (they should be equal), so:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object object;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition (with the delete keyword), you will lose the memory (and this is a memory leak). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer (*, because the new keyword creates a pointer), and also Obj and Object are inconsistent types (they should be equal), so:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object object;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

added 28 characters in body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition (with the delete keyword), you will lose the memory (and this is a memory breach). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer (*, because the new keyword creates a pointer), and also Obj and Object are inconsistent types (they should be equal), so:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object object;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition, you will lose the memory (and this is a memory breach). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer (*, because the new keyword creates a pointer), and also Obj and Object are inconsistent types (they should be equal), so:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object object;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition (with the delete keyword), you will lose the memory (and this is a memory breach). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer (*, because the new keyword creates a pointer), and also Obj and Object are inconsistent types (they should be equal), so:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object object;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

added 85 characters in body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition, you will lose the memory (and this is a memory breach). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer (*, newbecause the new keyword creates a pointer), and also Obj and Object are inconsistent types (they should be equal), so I would expect:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object obj;object;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition, you will lose the memory (and this is a memory breach). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer, new creates a pointer, so I would expect:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object obj;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

It will be created every iteration.

Assuming, you are not using it to add to a list (e.g. to use in later loops), what you better can do is make it in a global, you also don't need to use 'new', thus:

Object object;

Also, if you do not delete/remove the object at the end of each while condition, you will lose the memory (and this is a memory breach). Also, you run the risk of memory shortage (the Uno has only a few KB of memory).

What I also miss in your code is the pointer (*, because the new keyword creates a pointer), and also Obj and Object are inconsistent types (they should be equal), so:

Object* object = new Object();

If you only need the object within the condition and it can be removed in the next while, than you don't need to use new, so just declare it as a vaiable

Object object;

This also has the benefit that the (local) variable will be destroyed at the end of scope (which is at the end of the while).

Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59
Loading