To check if a new node can be inserted, I use dynamic memory allocation so if heap is full, then no new node returned (false returned). But if I created new node non-dynamically, it would come from the run time stack, right? But heap or run time stack, they are both just specially defined areas of memory where former requires explicity deallocation so the memory can be reused, while latter is automatic, so my ques is if I create new node non-dynamically and no memory left (which I'm sure we mean RAM), program will not compile, is that correct? Or b/c modern OS knows how to get access to secondary memory (hard drive), it'll slow down the program running, would that be correct?
Code:
bool front_insert(sll** head, int d)//returns TRUE if enough memory to create new node to insert into list
{
sll* newNode = new sll;//Q: what if I just use non-dyanmic allocated obj, then how to test if there is mem to create the new node or not?
if ( !newNode ) return false;
(*newNode).data = d;
if ( !(*head) )//if empty list
{
(*newNode).next = NULL;
*head = newNode;
}
else//else non-empty
{
(*newNode).next = *head;
*head = newNode;
}
return true;
}