views:

143

answers:

3

I am having a similar issue to this person. The primary difference being the application is NOT meant for a developer environment, and therefore I need to know how to optimize the space used by Sql Server (possibly per machine based on specs).

I was intrigued by Ricardo C's answer, particularly the following:

Extracted fromt he SQL Server documentation:

Maximum server memory (in MB)

Specifies the maximum amount of memory SQL Server can allocate when it starts and while it runs. This configuration option can be set to a specific value if you know there are multiple applications running at the same time as SQL Server and you want to guarantee that these applications have sufficient memory to run. If these other applications, such as Web or e-mail servers, request memory only as needed, then do not set the option, because SQL Server will release memory to them as needed. However, applications often use whatever memory is available when they start and do not request more if needed. If an application that behaves in this manner runs on the same computer at the same time as SQL Server, set the option to a value that guarantees that the memory required by the application is not allocated by SQL Server.

My question is: how does an application request memory from the OS when it needs it? Is this something built into compilation or something managed by the developer? The two primary apps running on this machine are Sql Server and the (fairly heavyweight) C# application I'm developing, and I'm almost certain we didn't specifically do anything in the realm of asking the OS for memory. Is there a correct/necessary way to do this?

A: 

Each time you create a new object, you are asking the .NET garbage collector to give you memory. If the GC has insufficient memory on the managed heap then it will ask the OS for more. As the other question says, although SQL server is meant to give the memory back it doesn't seem to do it very well. There is not going to be any hard and fast rules here, you will have to guess at some setting for SQL server and then test the performance. If you post some information about the server, database size, how much memory your application seems to require then I am sure people wil be happy to give you some suggestions for a starting configuration. One warning though, I think changing its memory limits requires a service re-start.

pipTheGeek
+1  A: 

Some applications allocate a lot of memory at startup, and then run their own memory management system on it. This page describes how this works in Photoshop, which is a "famous" instance of the technique. Many games do the same.

This can be good for applications that have particular allocation patterns, and that feel they can do a better job than the more generic memory manager provided by the runtime system.

In "managed" languages like C# I think this is very rare, and nothing you need to worry about.

unwind
A: 

It will depend on a few things - in particular the Operating System, and the language used.

For instance, under MacOS Classic, it was impossible to have more memory allocated after startup - we used to have to go and modify how much memory was allocated using the Finder, and then restart the application. Those were the bad old days.

Modern operating systems will allow for running processes to request more memory - for instance in C, you can use alloc(), malloc(), realloc() or similar to request chunks of memory. In dynamic languages, you just create objects or variables, and more memory is allocated.

In java, there is a limit as to how much memory the JVM has access to - and this can be changed by only restarting the JVM, and passing some arguments to it (sounds like the bad old days, doesn't it?).

In Objective-C, in addition to the malloc() family of functions, you can also create objects on the heap, using

[object alloc];

which is more often seen as

[[object alloc] init];

Note that this is slightly different to creating objects on the stack - if you are serious about programming learning the difference between these two might be useful, too :)

In summary - the programmer needs to ask the OS for more memory. This can be implicit (in dynamic languages, by creating objects, or by creating objects on the heap) or explicitly, such as in C by using alloc()/malloc()/etc.

Matthew Schinckel