When the solution matters

Tips...

Registration Documentation Knowledgebase Seminars / Training Technical Support Partner Central

Structure and Optimisation

How do I maximize the speed of 4D Server?

Start with choosing suitable hardware as discussed in ‘What is the best computer for 4D Server.

4D v6.5 or later are faster than 4Dv1.5/3.5.

You can also improve the speed of 4D applications considerably by the way you code them. The best way to learn to do this is to take a course in 4D client/server development (contact 4D Training). This course will teach you the principles of fast client/ server application development in detail. The most important things to do include:

Why can't I delete tables and fields?

Mainstream commercial relational database programs do not allow deletion of tables and fields. This is because each record in the database file is carefully structured around the fields and tables that exist when it was created. If a field or table is removed, either the program has to completely rewrite the data file, or each time a record is opened or a search is performed, it has to keep track of which older version of the record structure it should be using. In either case, the database will run much more slowly. Because speed is always a very important issue in any database management system, no mainstream commercial database management system permits deletion of fields or tables.

Why do I keep running out of memory?

If you keep running out of memory after 4D has been running for a while, your code is almost certainly generating what is known as a memory leak.

To understand how memory leaks occur, and thus how to avoid them, you need to understand how 4D uses its stack. A stack is a part of the electronic memory inside the computer which 4D uses to keep track of things you will want to go back to. There are two situations where you will want to go forward, then, back like this.

The first such situation is when one of your methods calls another. 4D must keep track of criteria such as which line will be executed after the method being called ends, and what the values of the first method's local variables are. 4D puts this information in a block of memory on the stack, then starts running the method called. If this method then calls another, 4D adds more information to the stack. In this way, as a sequence of methods calling methods, calling methods, builds up, blocks of information about the states of these methods builds up on the stack. When a method ends, its space on the stack is reclaimed, and the previous method is resumed using the information about it on the stack.

The other situation that is very similar to this is when a new form is opened in an existing window. There will usually be some other form showing at this point, so 4D saves this form's state on the stack: what record or records it is displaying, what information is showing in its variables, what method might be partly finished running which just opened the new form, and so on. In fact, the instruction to open a new form is basically the same kind as a method call.

Now, if your code makes a method call that never ends, or if it opens a form that never closes before opening another one in the same window, the information to keep track of this is never removed from the stack. And if your code does this repeatedly, you will eventually run out of memory due to what is called a stack overflow.

To avoid this, you must always let your methods end at some point, and you should usually close a form before you open a new one. A good rule with forms is that if your users could be opening a sequence of forms one of which they had open before, then you should structure your code to close each of these forms before opening the next one.


International | Company | Contact 4D | Site Map | Privacy Policy | © 4D UK 1995-2008 | Change font size: [A] [A] [A] | Print this page